private void ChangePinButton_Click(object sender, EventArgs e) { string newPin = NewPinTextBox.Text; string confirmPin = ConfirmTextBox.Text; if (newPin.Equals("") || confirmPin.Equals("")) { MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(NewPinTextBox, ConfirmTextBox, ConfirmTextBox); return; } if (!newPin.Equals(confirmPin)) { MessageBox.Show("New PIN and PIN confirmation do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(NewPinTextBox, ConfirmTextBox); return; } DBManager.UpdateValueWhere("Users", "Pin", newPin, "Login", LoggedUser.Login); MessageBox.Show("PIN has been successfully changed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); FormUtilities.EnableControls(DisabledControls); }
private void ForgotPasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Control[] controlsToBeDisabled = new Control[] { DontHaveAccButton, ForgotPasswordLinkLabel, LogInButton }; ForgotPasswordForm fpf = new ForgotPasswordForm(controlsToBeDisabled); FormUtilities.DisableControls(controlsToBeDisabled); fpf.Show(); }
private void DontHaveAccButton_Click(object sender, EventArgs e) { Control[] controlsToBeDisabled = new Control[] { DontHaveAccButton, ForgotPasswordLinkLabel, LogInButton }; RegisterForm rf = new RegisterForm(controlsToBeDisabled); FormUtilities.DisableControls(DontHaveAccButton, ForgotPasswordLinkLabel, LogInButton); rf.Show(); }
public ChangePasswordForm(User loggedUser, Control[] controls) { InitializeComponent(); DisabledControls = new Control[4]; controls.CopyTo(DisabledControls, 0); LoggedUser = loggedUser; FormUtilities.DisableControls(DisabledControls); }
private void ChangePinButton_Click(object sender, EventArgs e) { Control[] controlsToDisable = { ChangePasswordButton, ChangePinButton, LogOutButton, BackButton }; FormUtilities.DisableControls(controlsToDisable); int verificationCode = new Random().Next(100000, 999999); EmailManager.SendEmail(LoggedUser.Email, "changePin", LoggedUser.Login, verificationCode.ToString()); VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.ChangePin, verificationCode, controlsToDisable, LoggedUser.Login); vcf.Show(); }
private void RemindButton_Click(object sender, EventArgs e) { string login = LoginTextBox.Text; string email = EmailTextBox.Text; if (login.Equals("") || email.Equals("")) { MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Regex.IsMatch(email, "[^@]+@[^@]+\\.[^@]+")) { MessageBox.Show($"Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(EmailTextBox); return; } if (!DBManager.GetColumnValues("Users", "Login").Contains(login)) { MessageBox.Show($"Invalid user \'{login}\'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(LoginTextBox); return; } if (!DBManager.GetSingleValueWhere("Users", "Email", "Login", login).Equals(email)) { MessageBox.Show($"Email \'{email}\' is not associated with user \'{login}\'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(EmailTextBox); return; } int verificationCode = new Random().Next(100000, 999999); EmailManager.SendEmail(email, "forgot", login, verificationCode.ToString()); this.Close(); VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.Reminder, verificationCode, DisabledControls, login, email, /*password*/ DBManager.GetSingleValueWhere("Users", "Password", "Login", login)); vcf.Show(); FormUtilities.DisableControls(DisabledControls); }
private void ChangePasswordButton_Click(object sender, EventArgs e) { string oldPassword = OldPasswordTextBox.Text; string newPassword = NewPasswordTextBox.Text; string confirmPassword = ConfirmTextBox.Text; if (oldPassword.Equals("") || newPassword.Equals("") || confirmPassword.Equals("")) { MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(OldPasswordTextBox, NewPasswordTextBox, ConfirmTextBox); return; } if (!oldPassword.Equals(DBManager.GetSingleValueWhere("Users", "Password", "Login", LoggedUser.Login))) { MessageBox.Show("Invalid old password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(OldPasswordTextBox, NewPasswordTextBox, ConfirmTextBox); return; } if (newPassword.Length < 8) { MessageBox.Show("Password must be at least 8 characters long.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(OldPasswordTextBox, NewPasswordTextBox, ConfirmTextBox); return; } if (!newPassword.Equals(confirmPassword)) { MessageBox.Show("New password and password confirmation do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(OldPasswordTextBox, NewPasswordTextBox, ConfirmTextBox); return; } DBManager.UpdateValueWhere("Users", "Password", newPassword, "Login", LoggedUser.Login); MessageBox.Show("Password has been successfully changed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); FormUtilities.EnableControls(DisabledControls); }
private void OkButton_Click(object sender, EventArgs e) { string pin = PinTextBox.Text; if (pin.Equals("")) { MessageBox.Show("PIN is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!pin.Equals(DBManager.GetSingleValueWhere("Users", "Pin", "Login", LoggedUser.Login))) { MessageBox.Show("Invalid PIN.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PinTextBox); return; } PasswordLabel.Text = DBManager.GetSingleValueWhere("Accounts", "Password", "Id", PasswordLabel.ImageIndex.ToString()); PasswordLabel.Click -= PasswordClick; this.Close(); }
private void LogInButton_Click(object sender, EventArgs e) { string login = LoginTextBox.Text; string password = PasswordTextBox.Text; if (login.Equals("") || password.Equals("")) { MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!DBManager.GetColumnValues("Users", "Login").Contains(login)) { MessageBox.Show($"Invalid user \'{login}\'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox); return; } if (!DBManager.GetSingleValueWhere("Users", "Password", "Login", login).Equals(password)) { MessageBox.Show("Invalid password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox); return; } User loggedUser = new User(login, DBManager.GetSingleValueWhere("Users", "Email", "Login", login), password, DBManager.GetSingleValueWhere("Users", "Pin", "Login", login)); loggedUser.Id = Convert.ToInt32(DBManager.GetSingleValueWhere("Users", "Id", "Login", login)); EmailManager.SendEmail(loggedUser.Email, "alert", loggedUser.Login, DateTime.Now.ToString()); FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox); this.Hide(); MainForm mf = new MainForm(this, loggedUser); mf.Show(); }
private void ChangePasswordForm_FormClosing(object sender, FormClosingEventArgs e) { FormUtilities.EnableControls(DisabledControls); }
private void VerifyButton_Click(object sender, EventArgs e) { string enteredCode = CodeTextBox.Text; if (enteredCode.Equals(VerificationCode.ToString())) { switch (_Mode) { case Mode.Register: DBManager.AddUser(_User.Login, _User.Email, _User.Password, _User.Pin); this.Close(); MessageBox.Show($"User \'{_User.Login}\' has been created.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case Mode.Reminder: EmailManager.SendEmail(_User.Email, "reminder", _User.Password); this.Close(); MessageBox.Show("Your password has been sent to your email address.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case Mode.ChangePassword: this.Close(); ChangePasswordForm cpf = new ChangePasswordForm(_User, DisabledControls); cpf.Show(); break; case Mode.ChangePin: this.Close(); ChangePinForm _cpf = new ChangePinForm(_User, DisabledControls); _cpf.Show(); break; case Mode.Export: this.Close(); SaveFileDialog sfd = new SaveFileDialog(); sfd.ShowDialog(); string path = sfd.FileName; List <string> titles = DBManager.GetColumnValuesWhere("Accounts", "Title", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString()); List <string> logins = DBManager.GetColumnValuesWhere("Accounts", "Login", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString()); List <string> emails = DBManager.GetColumnValuesWhere("Accounts", "Associated_Email", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString()); List <string> passwords = DBManager.GetColumnValuesWhere("Accounts", "Password", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString()); try { using (StreamWriter sw = new StreamWriter(path)) { for (int i = 0; i < titles.Count; i++) { string accountRowForFile = "Title: " + titles[i] + "\tLogin: "******"\tAssociated email: " + emails[i] + "\tPassword: "******"Your data has been successfully exported.\n\nWarning: The exported file contains all of your accounts data. Be cautious when granting access to this file. Deleting the file\nfrom widely accessible disk space is recommended.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("Export has been cancelled.", "Export cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } } else { FormUtilities.ClearTextBoxes(CodeTextBox); MessageBox.Show("Invalid verification code.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void VerificationCodeForm_FormClosing(object sender, FormClosingEventArgs e) { FormUtilities.EnableControls(DisabledControls); }
private void RegisterForm_FormClosing(object sender, FormClosingEventArgs e) { FormUtilities.EnableControls(DisabledControls); }
private void RegisterButton_Click(object sender, EventArgs e) { string login = LoginTextBox.Text; string email = EmailTextBox.Text; string password = PasswordTextBox.Text; string confirm = ConfirmTextBox.Text; string pin = PinTextBox.Text; /* CHECK IF ALL FIELDS HAS INPUT*/ if (new string[] { login, email, password, confirm, pin }.Contains("")) { MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox); return; } /* CHECK IF LOGIN IS AVAILABLE */ if (DBManager.GetColumnValues("Users", "Login").Contains(login)) { MessageBox.Show($"Login \'{login}\' is already used.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox, ConfirmTextBox, PinTextBox); return; } /* CHECK EMAIL FORMAT */ if (!Regex.IsMatch(email, "[^@]+@[^@]+\\.[^@]+")) { MessageBox.Show($"Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(EmailTextBox, PasswordTextBox, ConfirmTextBox, PinTextBox); return; } /* CHECK PASSWORD LENGTH */ if (password.Length < 8) { MessageBox.Show($"Password must be at least 8 characters long.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox); return; } /* CHECK PASSWORD CONFIRMATION */ if (!password.Equals(confirm)) { MessageBox.Show("Password and password confirmation do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox); return; } int verificationCode = new Random().Next(100000, 999999); EmailManager.SendEmail(email, "greeting", login, verificationCode.ToString()); this.Close(); VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.Register, verificationCode, DisabledControls, login, email, password, pin); vcf.Show(); FormUtilities.DisableControls(DisabledControls); }
private void AddEditButton_Click(object sender, EventArgs e) { string title = TitleTextBox.Text; string login = LoginTextBox.Text; string associatedEmail = AssociatedEmailTextBox.Text; string password = PasswordTextBox.Text; string confirm = ConfirmTextBox.Text; if (title.Equals("")) { MessageBox.Show("Title is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox); return; } if (login.Equals("") && associatedEmail.Equals("")) { MessageBox.Show("Login or associated email is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox); return; } if (!associatedEmail.Equals("") && !Regex.IsMatch(associatedEmail, "[^@]+@[^@]+\\.[^@]+")) { MessageBox.Show($"Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(AssociatedEmailTextBox, PasswordTextBox, ConfirmTextBox); return; } if (password.Equals("")) { MessageBox.Show("Password is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox); return; } if (!password.Equals(confirm)) { MessageBox.Show("Password and password confirmation do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox); return; } if (_Mode == Mode.Add) { DBManager.AddAccount(title, login, associatedEmail, password, DBManager.GetSingleValueWhere("Users", "Id", "Login", LoggedUser.Login)); MessageBox.Show("Account has beed successfully added.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DBManager.UpdateValueWhere("Accounts", "Title", title, "Id", EdittedAccountId.ToString()); DBManager.UpdateValueWhere("Accounts", "Login", login, "Id", EdittedAccountId.ToString()); DBManager.UpdateValueWhere("Accounts", "Associated_Email", associatedEmail, "Id", EdittedAccountId.ToString()); DBManager.UpdateValueWhere("Accounts", "Password", password, "Id", EdittedAccountId.ToString()); MessageBox.Show("Account has beed successfully editted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); UpdateDisplay(); }
private void AccountForm_FormClosing(object sender, FormClosingEventArgs e) { FormUtilities.EnableControls(DisabledControls.ToArray()); }