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


Top 5 Contributors of the Month
david stephan

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.

 

Eg:

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

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

       Response.Write("shakeer " + str);

       Response.Write("
syed "
+ str1);

       Response.Write("
shakeer "
+ str);

 

OutPut:

shakeer =5950346F6943933C132C172DB40A006D
dotnetspark =
F5C9C47A833B6B72B6DFBE6EB9C1CF0DC132098E
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");

Conn.Open();

SqlCommand cmd=new SqlCommand("insert into loginuser(name,password) values('"+user_name +"','"+ hasspassword +"')",conn);

cmd.ExecuteNonquery();

 


 Subscribe to Articles

     

Further Readings:

Responses

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