private void btnAdd_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(textBox1.Text)) { throw new Exception("Enter Username"); } else if (string.IsNullOrEmpty(textBox2.Text)) { throw new Exception("Enter Password"); } else if (string.IsNullOrEmpty(textBox3.Text)) { throw new Exception("Confrim Password"); } else if (textBox2.Text == textBox3.Text) { if (PasswordEncryptor.Encrypt(txtcreateUserAdmin.Text) == AdminLog.AdminPass) { //call the insert class AdminLog.CreateAdmin(textBox1.Text, textBox2.Text); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); txtcreateUserAdmin.Text = ""; MessageBox.Show("Admin Created Succesfully\n\nPlease set security questions\n" + "after now, to enable password reset\n" + "in case password is forgotten", "Create Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); dataAccess.Description = "Added a new user"; dataAccess.Activities(); } else { throw new Exception("Enter Currently Logged in admin Password"); } } else { throw new Exception("Password Mismatch"); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void txtConpass_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (char)Keys.Enter) { try { if (string.IsNullOrEmpty(txtusername.Text)) { throw new Exception("Enter Username"); } else if (string.IsNullOrEmpty(txtpass.Text)) { throw new Exception("Enter Password"); } else if (string.IsNullOrEmpty(txtConpass.Text)) { throw new Exception("Confrim Password"); } else if (txtpass.Text == txtConpass.Text) { //call the insert class AdminLog.CreateAdmin(txtusername.Text, txtpass.Text); MessageBox.Show("Admin Created Succesfully\n\nPlease Set security questions after you\n" + "must have log in, to help Reset\n" + " your password if forgotten, thanks.", "Create Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); var admin = new LoginForm(); this.Close(); admin.Show(); } else { throw new Exception("Password Mismatch"); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Create Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }