我有一个简单的C#窗体,它充当登录,但也有一个窗体来更改用户的密码。验证和更改用户的密码
当你点击更改密码时,表单将加载一个当前密码,新通行证和确认新通行证的文本框,以及一个保存按钮。
我已经在标签中存储了用户名,以便当前的密码可以检查,如果它是从数据库中是否有效。
我在我在Microsoft SQL Server 2008中
代码是迄今为止如下创建的表中存储这些。
SqlConnection connect = new SqlConnection(str);
connect.Open();
string username = label_username.Text;
string password = textBox_Current.Text;
string newPassword = textBox_New.Text;
string confirmPassword = textBox_Verify.Text;
string sqlquery = "UPDATE [Member] SET [email protected] where [email protected]";
SqlCommand cmd = new SqlCommand(sqlquery, connect);
cmd.Parameters.AddWithValue("@newpass", textBox_Verify.Text);
cmd.Parameters.AddWithValue("@username", label_username.Text);
cmd.Parameters.AddWithValue("@password", textBox_Current.Text);
cmd.Connection = connect;
cmd.ExecuteNonQuery();
sqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if ((textBox_New.Text == reader["newPassword"].ToString()) & (textBox_Verify.Text == (reader["confirmPassword"].ToString()))) { }
}
MessageBox.Show("Password Changed Successfully!");
this.Close();
在执行上面的代码,密码改变,但我想:
- 检查验证一样,如果用户已经在当前密码输入错误的密码。
- newpassword并确认密码。
- 当第一次保存底部空密码用户点击数据库不应该保存,而应该给消息“请输入密码”
如何才能做到这一点?
不要将密码存放在纯文本。相反,请使用安全哈希。 – SLaks
当然,你哈希这些密码,你只是简化它为我们的利益,对吧?对!? –
我会建议只使用成员身份验证,附带API和一切,没有必要重新发明轮子 – BrokenGlass