Encrypting password and store in a Database using sqlserver

Posted by in ASP.NET category on for Intermediate level | Views : 10580 red flag

Encrypting password and store in a Database using sqlserver

Encrypting password

HashFunction:To Encrypt a Password use HashFunction.HashFunction sends your password to a function which spits out your password all garbled. To hash a password, you can use the built in method called HashPasswordForStoringInConfigFile.


 You can call it like this:

 FormsAuthentication.HashPasswordForStoringInConfigFile("password","md5"). The first parameter is the password to be hashed. The second parameter is either "md5" or "sha1" depending on which hashing function you use.



string str = FormsAuthentication.HashPasswordForStoringInConfigFile("dotnetfunda ", "MD5");

       string str1 = FormsAuthentication.HashPasswordForStoringInConfigFile("dotnetfunda.com", "sha1");

       Response.Write("dotnetfunda " + str);

       Response.Write("<br>dotnetfunda.com " + str1);

       Response.Write("<br>dotnetfunda " + str);



dotnetfunda =B9B93AF7A7DA8881888EDD632D7A23E7

dotnetfunda.com =0E34AD60C96D6A480C0FC9D2B82796F3F43EC833
dotnetfunda =B9B93AF7A7DA8881888EDD632D7A23E7


storing Hashvalue in a database:


create loginuser Table with two columns as username varchar(50),password varchar(50).

Drag and drop two  Textboxes as txtusername and txtpassword on a WebPage.


String user_name=txtusername.Text;

String hasspassword= FormsAuthentication.HashPasswordForStoringInConfigFile(txtpassword.Text,"MD5”);

//Converting a password in to HashPassword


SqlConnetion conn=New SqlConnection(“your connection”);


SqlCommand cmd=new SqlCommand(“insert into loginuser(username,password) values(‘”+user_name +”’,’”+ hasspassword +”’)”,conn);



Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Syed Shakeer Hussiain P
Member Level:
Member Status: Member
Member Since: 2/5/2009 3:12:18 AM
Country: India
Syed Shakeer Hussain
Shakeer Hussain has completed his Master of Computer Applications degree from Deccan College of engg and technology of Osmania University.He is a MVM of www.dotnetspider.com.He has good experience in the areas of ASP.NET, C#.NET, VB.NET, SQL SERVER 2000/2005 and Windows Mobile. He has worked in Windows Mobile,Web Applicatin and ERP projects.

Login to vote for this post.

Comments or Responses

Posted by: Avicool08 on: 5/15/2009
Good article, simple way its explained... keep it up syedshakeer...
Posted by: Thanos on: 8/17/2018 | Points: 25
I must be this is the amazing blog here to like by the many web users online have to access in to main setting of your browser for svchost.exe netsvcs high memory usage click here https://windowsclassroom.com/how-fix-svchost-exe-netsvcs-high-usage-windows and Carrie to simple steps for open easily to task manager thanks.

Login to post response

Comment using Facebook(Author doesn't get notification)