I have a single form that is "divided" into two portions. First portion has "User ID" (text box), "Security Question" (combo) and answer to "Security Question" (text box).It has a "Submit Button" which checks database for matching security/Answer. If match is found, second portion below is enabled.
Second portion has "New Password" & "Confirm Password", and "Change" button.
What I want to achieve is verify security question and answer match for the "UserID" above. That I can do. However, I want to pass the "User ID" to the click event of "Change" button, so I do not have to ask for "User ID" again, and do not change password for everyone in the database.
Here is part of my code:
private void btnchange_Click(object sender, EventArgs e)
{
{
//How do I pass UserID from "Submit"?
if (txtnewpassword.Text == "")
{
MessageBox.Show("Please enter a new password...");
}
if (txtconfirmpassword.Text == "")
{
MessageBox.Show("Please confirm your new password...");
}
else
{
try
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLlocaldb; Initial Catalog = AdminAuthentication; Integrated Security = True");
con.Open();
if (txtnewpassword.Text == txtconfirmpassword.Text)
{
string query = " update UserRegistration set [Password]= '" + txtnewpassword.Text + "' where UserID = '" /*+pass USERID here?*/ + "'";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Password Succesfully Updated!");
txtconfirmpassword.Clear();
txtnewpassword.Clear();
txtuserid.Clear();
this.Hide();
Loginsystem ls = new Loginsystem();
ls.Show();
}
else
{
MessageBox.Show("The passwords do not match.Try again");
txtconfirmpassword.Clear();
txtnewpassword.Clear();
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error Occured" + ex);
}
}
}
}