I have a simple C # windows form that acts like a login, but also has a form for changing a user's password.
When you click the "Change Password" button, the form is loaded with the text field of the current password, a new pass and confirmation of a new pass and one save button.
I saved the username in a shortcut so that the current password can be checked if it is valid from the database or not.
I save them in a table that I created in Microsoft SQL Server 2008.
The code is as follows.
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 Password=@newpass where Username=@username "; 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();
When the above code is executed, the password is changed, but I want:
- check the check, for example, if the user has typed the wrong password in the current password.
- newpassword and confirm the password.
- when the user clicks first to save the lower empty password, it should not be stored in the database, rather, it should indicate the message "please enter the password"
How can I do that?
source share