Salt + Hashed Password store in Database

Posted by Nkkppp under ASP.NET on 10/9/2012 | Points: 10 | Views : 1587 | Status : [Member] | Replies : 1
Hi All,

Can anyone please provide the code to hash the password along with Salt and save it into the database.

Also provide the code to verify the password during login against the one in database.

I have searched a lot in google but couldn't get a very simple implementation with proper explanation.

So provide the code for a Login page and Register Page to store hashed password in Database and Verify.

Regards,
Prathap.




Responses

Posted by: Self-Innovator on: 10/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi u can try this,
password can be store in two different hashing password algorithms MD5 and SHA1, try encrypting using Forms authentication like Below
On Register Click

BtnRegister_Click()

{
string UserId = txtUser.Text.Trim();
Session["UserId"] = UserId;
String Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(),"SHA1");
//the above line will store the password in hash format in the table
{
SqlConnection cnn = new SqlConnection(Conn);
SqlCommand cmd = new SqlCommand("spGetUsers", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", UserId);
cmd.Parameters.AddWithValue("@Pwd", Pwd);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
if (ds.Tables[0].Rows.Count >0)
{
if(Pwd==ds.Tables[0].Rows[0]["Password"].ToString());
{
Response.Redirect("Home.aspx");
}
else
{
Response.Redirect("Loginaspx");
}
}
}






Join Hands Change lives
Thanks & Regards
Straight Edge Society

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response