I am creating a windows login form with an option in case you forget your password, in which you will click a button to direct you to another from where you can answer security questions and stuff to confirm your identity before the password is retrieved from the datatable and displayed in a MessageBox
. My code is already able to verify the identity but how do I obtain the value of the password from the same row that the Username is entered in?
I have absolutely no programming background and or knowledge and would greatly appreciate if you can help with examples or codes thanks :)
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Daniel Koh\Documents\AccountData.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From [Table] where Username='" + textBox1.Text + "' and EmployeeId ='" + textBox2.Text + "' and SecurityQuestionAnswer='" + textBox3.Text + "' and SecurityQuestionType='" + comboBox1.SelectedItem.ToString() + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
SqlConnection.ClearAllPools();
if ((dt.Rows[0][0].ToString() == "1"))
{
string username = textBox1.Text;
string password = (from DataRow dr in dt.Rows
where (string)dr["username"] == username
select (string)dr["Password"]).FirstOrDefault();
MessageBox.Show(password);
}
else
{
MessageBox.Show("Please check your Username, Security Question Answer and EmployeeID");
}
}