//boolean method to validate username public void ValidateUsernameAndPassword(Receptionists recep) { //validate username and password if (username.Length == 0) { txtUsername2.BackColor = Color.White; lblErrMsg3.Text = ""; lblErrMsg3.Text = "*"; } else if (password.Length == 0) { lblErrMsg4.Text = ""; lblErrMsg4.Text = "*"; txtPassword2.BackColor = Color.White; } else if (recep.Username.Equals(username) && recep.Password.Equals(password)) { lblErrMsg3.Text = ""; lblErrMsg3.Text = ""; //show main menu form frmMain main = new frmMain(); main.Show(); } else if (recep.Username != username) { txtUsername2.ForeColor = Color.Red; lblErrMsg3.Text = "INVALID USERNAME!!"; } else if (recep.Password != password) { txtPassword2.ForeColor = Color.Red; lblErrMsg4.Text = "INVALID PASSWORD!!"; } }
// method to compare new password public void ChangePasswords(Receptionists recep) { if (txtNewPass2.Text.Equals(txtConfirmPass2.Text)) { try { sConn = "Provider = Microsoft.ACE.OLEDB.12.0;" + "Data Source = ArmaniDevine.accdb"; dbConn = new OleDbConnection(sConn); dbConn.Open(); //assign the values to the properties recep.NewPass = txtNewPass2.Text; recep.Username = txtUsername2.Text; recep.Password = txtPassword2.Text; sql = "UPDATE Receptionists SET Password='******' WHERE (Username='******' AND Password='******')"; dbCmd = new OleDbCommand(); dbCmd.CommandText = sql; dbCmd.Connection = dbConn; dbCmd.ExecuteNonQuery(); dbAdapter = new OleDbDataAdapter(); dbAdapter.UpdateCommand = dbCmd; MessageBox.Show("YOUR PASSWORD HAS BEEN SUCCESSFULLY CHANGED...", "Success Message"); dbConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("YOUR PASSWORDS DO NOT MATCH!!!...", "Error Message"); txtNewPass2.Text = ""; txtConfirmPass2.Text = ""; } }
private void Receptionist_Load(object sender, EventArgs e) { //instanstiate the class object recep = new Receptionists(); txtUsername2.Focus(); txtPassword2.PasswordChar = '*'; txtNewPass2.PasswordChar = '*'; txtConfirmPass2.PasswordChar = '*'; txtPassword2.MaxLength = 9; txtUsername2.MaxLength = 30; txtNewPass2.MaxLength = 9; txtConfirmPass2.MaxLength = 9; lblNewPass2.Visible = false; lblConfirmPass2.Visible = false; txtNewPass2.Visible = false; txtConfirmPass2.Visible = false; btnChangePassword2.Hide(); }