Save Password in encript form.

This code snippets shows how to save password in encripted form.

This code snippets shows how to save password in encripted form into database:

First of all we will take the varbinary datatype for password field.

also we will convert that field in our query when we will save that like.

insert into TableName (password) values (convert(varbinary, 'Password'))

and in store procedure:

insert into TableName
convert(varbinary, @Password)

Vivek Sharma

Related Articles

More articles: Password encryption Encryption Decryption


Author: prasad12 May 2010 Member Level: Silver   Points : 1

Hi Vivek,

Itried u'r sample i am getting Must declare the scalar variable "@password".


Author: mox shah17 May 2010 Member Level: Gold   Points : 1


string password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtpassword.Text, "sha1");

this string password stores password in encrypted form

let me know if you have any query

Author: Sudhir20 May 2010 Member Level: Gold   Points : 1

Hi prasad,

try this code i had modified here.
declare @Password varchar(max)
set @Password='actual password'

insert into TableName(Password)values(convert(varbinary, @Password));

:) happy coding

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: