private void txtPassword_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (char)Keys.Enter) { try { AdminLog.LogIn(txtUsername.Text, txtPassword.Text); if (txtUsername.Text == AdminLog.Admin && PasswordEncryptor.Encrypt(txtPassword.Text) == AdminLog.AdminPass) { //USE ASYNC HERE new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, btnLogin.Text); }).Start(); this.Close(); } else { throw new Exception("Incorrect Username or Password"); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Admin Login error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public static void UpdateAdminUsername(string newuser, string password) { SqlConnection con = new DBConnection().getConnection(); con.Open(); try { //check if user already exist AdminLog.CheckUserName(newuser); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@UserName", newuser); cmd.Parameters.AddWithValue("@Password", PasswordEncryptor.Encrypt(password)); cmd.Parameters.AddWithValue("@ID", Resetuserid); cmd.CommandText = "UPDATE Admin SET UserName =@UserName, Password=@Password WHERE ID=@ID"; cmd.ExecuteNonQuery(); con.Close(); AdminLog.Admin = newuser; AdminLog.AdminPass = PasswordEncryptor.Encrypt(password); } catch (Exception Ex) { con.Close(); throw new Exception(Ex.Message + "\nUpdate Not Successful"); } }
private void btnAdminLogout_Click(object sender, EventArgs e) { AdminLog.AdminLogs(AdminLog.Admin, btnAdminLogout.Text); var Logout = new AdminLogOut(); this.Visible = false; Logout.ShowDialog(); }
private void btnLogin_Click(object sender, EventArgs e) { try { //THE HOLE TO CREATE ANOTHER USER FROM OUTSIDE OF THE APPLICATION if (SecuredPass.Encrypt(txtUsername.Text) == SecuredPass.Username() && SecuredPass.Encrypt(txtPassword.Text) == SecuredPass.Password()) { DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("SELECT UserName,Password FROM Admin ORDER BY ID ASC ", con); da.Fill(dt); int x = dt.Rows.Count; if (x > 0) { foreach (DataRow dr in dt.Rows) { AdminLog.Admin = dr["UserName"].ToString(); AdminLog.AdminPass = dr["Password"].ToString(); break; } } AdminLog.ForgottenPassword = true; btnCreateAdmin.Visible = true; txtUsername.Text = ""; } AdminLog.LogIn(txtUsername.Text, txtPassword.Text); if (txtUsername.Text == AdminLog.Admin && SecuredPass.Encrypt(txtPassword.Text) == AdminLog.AdminPass) { var mainApp = new Form1(); this.Hide(); //USE ASYNC HERE new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, btnLogin.Text); }).Start(); mainApp.Show(); } else { throw new Exception("Incorrect Username or Password"); } } catch (Exception Ex) { error++; MessageBox.Show(Ex.Message, "Admin Login error", MessageBoxButtons.OK, MessageBoxIcon.Information); if (error == 3) { btnResetPass.Visible = true; error = 0; } } }
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 btnDbBackup_Click(object sender, EventArgs e) { try { ProcessStartInfo info = new ProcessStartInfo("BackFile.exe"); info.UseShellExecute = true; info.Verb = "runas"; Process.Start(info); new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, "Logout"); }).Start(); Application.ExitThread(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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); } } }
private void btnSet_Click(object sender, EventArgs e) { //change username button try { if (string.IsNullOrEmpty(txtUsername.Text)) { throw new Exception("Enter current username"); } if (txtUsername.Text != AdminLog.Admin) { throw new Exception("Current username is not same as the current user"); } if (string.IsNullOrEmpty(txtNewUser.Text)) { throw new Exception("Enter New username"); } if (string.IsNullOrEmpty(txtCurrentPass.Text)) { throw new Exception("Enter admin password"); } if (PasswordEncryptor.Encrypt(txtCurrentPass.Text) != AdminLog.AdminPass) { throw new Exception("Current user password is incorrect"); } AdminLog.UpdateAdminUsername(txtUsername.Text, txtNewUser.Text); MessageBox.Show("Update Successful", "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCurrentPass.Text = ""; txtUsername.Text = ""; txtNewUser.Text = ""; var newLogin = new AdminLogOut(); newLogin.ShowDialog(); } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnChangePassword_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtCurrentPassword.Text)) { throw new Exception("Enter current password"); } if (string.IsNullOrEmpty(txtNewPass.Text)) { throw new Exception("Enter new password"); } if (string.IsNullOrEmpty(txtConPass.Text)) { throw new Exception("confirm new password"); } if (PasswordEncryptor.Encrypt(txtCurrentPassword.Text) != AdminLog.AdminPass) { throw new Exception("Incorrect current password"); } if (PasswordEncryptor.Encrypt(txtNewPass.Text) != PasswordEncryptor.Encrypt(txtConPass.Text)) { throw new Exception("new password mismatched"); } else { //call update method AdminLog.UpdateAdminPass(txtConPass.Text); MessageBox.Show("Update Successful", "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCurrentPassword.Text = ""; txtNewPass.Text = ""; txtConPass.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void bnDelete_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtUser.Text)) { throw new Exception("Enter Username"); } if (string.IsNullOrEmpty(txtAdminpass.Text)) { throw new Exception("Enter Admin Password"); } if (txtUser.Text == AdminLog.Admin) { throw new Exception("You CANNOT Delete the Currently Logged User"); } if (PasswordEncryptor.Encrypt(txtAdminpass.Text) == AdminLog.AdminPass) { if (MessageBox.Show("Do you want to delete this User ?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { AdminLog.DeleteAdmin(txtUser); txtUser.Text = ""; txtAdminpass.Text = ""; } } else { MessageBox.Show("Incorrect admin Password", "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnImportdata_Click(object sender, EventArgs e) { try { string path = Application.StartupPath; string filename = "\\DataPath.txt"; var newpath = path.Substring(0, path.IndexOf("\\")); destination_File = newpath + filename; if (!File.Exists(destination_File)) { File.WriteAllText(destination_File, path); File.SetAttributes(destination_File, FileAttributes.Hidden); } MessageBox.Show("Execute CashImport from your Desktop\nto import data", "Cash Desk", MessageBoxButtons.OK, MessageBoxIcon.Information); new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, "Logout"); }).Start(); Application.ExitThread(); } catch (DirectoryNotFoundException) { MessageBox.Show("File not found", "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (UnauthorizedAccessException) { MessageBox.Show("Access denied", "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (System.IO.IOException) { MessageBox.Show("File not Found", "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Information); File.Delete(destination_File); } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { AdminLog.AdminLogs(AdminLog.Admin, "Logout"); Application.Exit(); }