Search This Blog

Saturday, April 7, 2012

Authenticating Users With Encryption Of Passwords


BtnLogin_Click()

{ 

string UserId = txtUser.Text.Trim();

Session["UserId"] = UserId;

String Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(),"MD5");

{

            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");

                }

            }

}



While Registering Store The Pwd in this Encrypted Format 
String Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(),"MD5"); 

Both are Applicable MD5 or SHA1 

No comments:

Post a Comment