I'm trying to allow a user to reset/update password in the event that they have forgotten it matching the username and their full in order reset the password. However; I keep getting the error message,Username and name is not matching even they match.
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
byte up;
protected void btn_update_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
try
{
string un, pw;
un = txtUsername.Text;
pw = Encrypt(txt_npassword.Text, "mykey");
SqlCommand command = new SqlCommand("PP_spReset", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = un;
command.Parameters.Add("@password", SqlDbType.VarChar).Value = pw;
con.Open();
int rowupdated = command.ExecuteNonQuery();
if (rowupdated > 0)
{
Response.Redirect(@"~/Account/Login.aspx"); ;
}
else
{
lbl_msg.Text = "Username does not exist";
}
}
catch (Exception ex)
{
throw ex;
}
}
public string Encrypt(string source, string key)
{
TripleDESCryptoServiceProvider desCryptoProvider = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashMD5Provider = new MD5CryptoServiceProvider();
byte[] byteHash;
byte[] byteBuff;
byteHash = hashMD5Provider.ComputeHash(Encoding.UTF8.GetBytes(key));
desCryptoProvider.Key = byteHash;
desCryptoProvider.Mode = CipherMode.ECB; //CBC, CFB
byteBuff = Encoding.UTF8.GetBytes(source);
string encoded =
Convert.ToBase64String(desCryptoProvider.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
return encoded;
}