private void btnLogin_Click(object sender, EventArgs e) { //Do nothing if user name or password is empty. if ((txtUserName.Text == String.Empty) || (txtUserName.Text == null)) { return; } if ((txtPassword.Text == String.Empty) || (txtPassword.Text == null)) { return; } userAccount = ApplicationObjects.AuthenticateUser(txtUserName.Text, txtPassword.Text); if (userAccount.UserName == "invalid" && userAccount.PasswordHash == "invalid") { MessageBox.Show("Failed to authenticate with inputted username and password." , "Authentication Failed" , MessageBoxButtons.OK , MessageBoxIcon.Exclamation); Logout(); return; } if (userAccount.HighestPermission == null) { MessageBox.Show("Invalid permissions token. Please contact your manager." , "Authentication Failed" , MessageBoxButtons.OK , MessageBoxIcon.Exclamation); return; } //Auto forward them to the highest permission user page. switch (userAccount.HighestPermission) { case (Permission.OperationsManager): ShowDashBoardSelectionForm(userAccount, this); this.Hide(); break; case (Permission.SalesPerson): ShowSalesEmployeeForm(userAccount, this); this.Hide(); break; case (Permission.WorkSpecialist): ShowWorkSpecialistForm(userAccount, this); this.Hide(); break; case (Permission.StockClerk): ShowStockClerkForm(userAccount, this); this.Hide(); break; } }
protected void submitBtn_Click(object sender, EventArgs e) { if (lblError.Visible == true) { lblError.Text = null; } //Do nothing if user name or password is empty. if ((txtUserName.Text == String.Empty) || (txtUserName.Text == null)) { return; } if ((txtPassword.Text == String.Empty) || (txtPassword.Text == null)) { return; } // get user account information from the database userAccount = ApplicationObjects.AuthenticateUser(txtUserName.Text, txtPassword.Text); //If the user information is invalid, return error. if (userAccount.UserName == "invalid" && userAccount.PasswordHash == "invalid") { lblError.Text += "Failed to authenticate with inputted username and password, Authentication Failed"; lblError.Visible = true; return; } if (userAccount.HighestPermission == null) { lblError.Text += "Invalid permissions token. Please contact Help-Desk, Authentication Failed"; lblError.Visible = true; return; } txtError.Text = "Success"; txtError.Visible = true; //redirect users based on permissions switch (userAccount.HighestPermission) { case (Permission.Manager): ShowManagerMainForm(userAccount); break; case (Permission.Customer): ShowCustomerPage(userAccount); break; } }
private void btnAccept_Click(object sender, EventArgs e) { //Authenticate user userAccount = ApplicationObjects.AuthenticateUser(this.txtUserID.Text, this.txtOldPwd.Text); if (userAccount == null || userAccount.HighestPermission == null) { DialogResult result = MessageBox.Show("Failed to authenticate user.", "Authentication failed!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand); if (result == DialogResult.Retry) { return; } else { _loginForm.Logout(); this.Close(); return; } } //Verify the text boxes are not empty if (!(this.txtNewPwd.Text == String.Empty) && !(this.txtConfirmPwd.Text == String.Empty)) { //Validate new and confirmed passwords match if (String.Compare(this.txtNewPwd.Text, this.txtConfirmPwd.Text) != 0) { DialogResult result = MessageBox.Show("Your new and confirmed passwords did not match.", "Password mismatch", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand); if (result == DialogResult.Retry) { return; } else { _loginForm.Logout(); this.Close(); return; } } } else { DialogResult result = MessageBox.Show("Both new and confirmed password boxes must be populated.", "Invalid input!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand); if (result == DialogResult.Retry) { return; } else { _loginForm.Logout(); this.Close(); return; } } //Change password userAccount.PasswordHash = this.txtNewPwd.Text; ApplicationObjects.ChangePassword(userAccount); //Logout to re-authenticate MessageBox.Show("Password change complete. Please re-log in.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.None); _loginForm.Logout(); this.Close(); }