Hey all,
A quick question, i've been picking my brain and browsing the net for a few hours now and still can't get any further.
I have a simple C# windows form which acts as a login, but also has a form to change the password of a user. When you click on Change Password the form loads with a text box for username, current password, new pass and confirm new pass.
I am storing these in a SQL Database which I created in VS2008.
The code is as follows so far. (connection string part with try/catch deleted, it works, and is at the top of this void)
private void btnConfirm_Click(object sender, EventArgs e)
string username = txtUser.Text;
string password = txtCurrPass.Text;
string newPassword = txtNewPass.Text;
string confNewPassword = txtConfirmNewPass.Text;
string sqlquery = "UPDATE users SET username = " + txtUser.Text + " AND password = " + txtConfirmNewPass.Text + "'";
SqlCommand cmd = new SqlCommand(sqlquery, cn);
cmd.Connection = cn;
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if ((txtNewPass.Text == reader["newPassword"].ToString()) & (txtConfirmNewPass.Text == (reader["confNewPassword"].ToString())))
{
MessageBox.Show("Password Changed!");
}
}
}
Ideally I would like the user to enter their username and current password, then their new pass and then confirm their new password. Then when they hit the button, it checks if the two new passwords match and if they do it updates the data in the database.