.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Encrypting a Password and store in DataBase using SqlServer

Posted By:Syed Shakeer Hussain       Posted Date: May 14, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

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("shakeer ", "MD5");

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

       Response.Write("shakeer " + str);

syed "
+ str1);

shakeer "
+ str);



shakeer =5950346F6943933C132C172DB40A006D
dotnetspark =
shakeer =5950346F6943933C132C172DB40A006D


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(name,password) values('"+user_name +"','"+ hasspassword +"')",conn);



 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend