Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends,
i am developing an application in VB.NET and i want my application to be secured and that is why i want to know how can i encrypt the password and store the hash string into Database.

and when user logs-in it should convert the password into hash and comapre to the stored password and authorise the user.

Thanks.
Posted
Updated 15-Oct-11 1:27am
v2

 
Share this answer
 
Comments
Jαved 15-Oct-11 8:58am    
Thanks OriginalGriff.
Imports System.Text
Imports System.Security.Cryptography

Public Function computeHash(ByVal strPassword As String) As String
Dim plainTextBytes() As Byte = Encoding.UTF8.GetBytes(strPassword)
Dim hash As HashAlgorithm = New SHA256Managed()
Dim hashBytes() As Byte = hash.ComputeHash(plainTextBytes)
Dim hashvalue As String = Convert.ToBase64String(hashBytes)
Return hashvalue
End Function
By using the above function encrypt your password and store the encrypted string into database. On login compare the hash value of textbox with the database value that you have saved.
 
Share this answer
 
Comments
Jαved 15-Oct-11 8:58am    
Thanks Muhammad Shahid Farooq.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900