JIALIH_H
JIALIH_H
2018-12-12 11:23

c#winfrom修改MD5加密的密码

  • c#winfrom
  • sql server
  • md5

sql server数据库中有一个用MD5加密的密码,现在要在c#winform中修改密码,并然后新密码保存至数据库中,我有一串代码,可以修改,但是重新登录时,一直显示密码错误,我能确保我输入的密码是我改好的密码,求解决。

SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString =
"Server=(local);Database=DB_Equipment;Integrated Security=sspi";
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandText =
        "UPDATE tb_administrator"
        + " SET Password = HASHBYTES('MD5',@Password)"
        + " WHERE No=@No;";
sqlCommand.Parameters.AddWithValue("@Password", this.txb_newpwd.Text.Trim());
sqlCommand.Parameters.AddWithValue("@No", UserHelper.administratorNo);
sqlConnection.Open();
int rowAffected = sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
if (rowAffected == 1)
{
       MessageBox.Show("密码修改成功,请重新登录!");
       UserHelper.userPassword = txb_newpwd.Text.Trim();
       this.Hide();
       frm_Home frm_home = new frm_Home();
         frm_home.Show();
}
else
{
       MessageBox.Show("密码修改失败!");
}                       
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐