Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm having trouble logging in my database after I used BCrypt to hash login password. Below is a snippet of my code.

private void button_Click(object sender, EventArgs e)

{


SqlConnection conn = new SqlConnection(………………………………….);







string userID =Microsoft.VisualBasic.Interaction.InputBox ("Please enter User ID", "User ID"); // prompt user to enter user ID

string pwd = Microsoft.VisualBasic.Interaction.InputBox ("Please enter password", "PASSWORD");

// promt user to enter a password

string salt = BCryptHelper.GenerateSalt(8);

string hashPwd = BCryptHelper.HashPassword (pwd, salt);

bool checkPwd = BCryptHelper.CheckPassword (pwd, hashPwd);



conn.Open ();

SqlCommand sqlCmd = new SqlCommand ("UPDATE Table_Person SET Password = @Password WHERE User ID = @UserID", conn);

sqlCmd.Parameters.AddWithValue ("@Password", hashPwd);

sqlCmd.Parameters.AddWithValue ("@UserID", userID);

sqlCmd.ExecuteNonQuery ();


conn.Close ();

}

What I'm my doing wrong here? The password field from my database table has been hashed, but how do I decrypt it back? Can someone help please.
Posted
Comments
[no name] 6-Jul-14 10:00am    
You don't. Hashing is a one way street. You need to compare the hashes.
Member 10703465 7-Jul-14 8:07am    
Thanks. The compared hashes works perfect :)

1 solution

As I said when you asked this question yesterday: How to store password on a SQL table using BCrypt[^]

Don't encrypt passwords. Hash them: Password Storage: How to do it.[^]
 
Share this answer
 

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