我有一個簡單的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