private void Editbtn_Click(object sender, EventArgs e) { if (txtanswer.Text == answer) { if (txtpassword.Text == txtnewpassword.Text) { if (txtpassword.Text != "") { if (dbhelper.openConnection()) { try { string query = "UPDATE tblaccount SET password = @pass WHERE username = @user"; MySqlCommand cmd = new MySqlCommand(query, dbhelper.getConnection()); cmd.Parameters.AddWithValue("user", txtusername.Text); cmd.Parameters.AddWithValue("pass", MD5Hasher.GetMd5Hash(txtnewpassword.Text)); cmd.ExecuteNonQuery(); MessageBox.Show("Your password is changed!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("New password cant\'t be blank!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("New password mismatched!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } dbhelper.closeConnection(); } else { MessageBox.Show("Answer mismatched!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private bool validate_login(string user, string pass) { dbconnection.openConnection(); string query = "Select * from tblaccount where username=@user and password=@pass "; MySqlCommand cmd = new MySqlCommand(query, dbconnection.getConnection()); cmd.Parameters.AddWithValue("@user", user); cmd.Parameters.AddWithValue("@pass", MD5Hasher.GetMd5Hash(pass)); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { dbconnection.closeConnection(); return(true); } else { dbconnection.closeConnection(); return(false); } }