/// <summary> /// Event handler for button click in <see cref="CreateAccountWindow"/>. /// <para>When Submit is clicked, the text fields check to make sure valid data is entered /// using regular expressions in <see cref="RegexUtilities"/></para> /// </summary> /// private void CreateAccountSubmitButton_Click(object sender, RoutedEventArgs e) { #region TextField Error Checking String errorMessage = null; if (string.IsNullOrWhiteSpace(this.firstNameTextBox.Text)) { errorMessage += " \"First Name\" "; } if (string.IsNullOrWhiteSpace(this.lastNameTextBox.Text)) { errorMessage += " \"Last Name\" "; } if (string.IsNullOrWhiteSpace(this.emailTextBox.Text)) { errorMessage += " \"Email\" "; } if (string.IsNullOrWhiteSpace(this.userPasswordBox.Password)) { errorMessage += " \"Password\" "; } if (string.IsNullOrWhiteSpace(this.securityQuestionTextBox.Text)) { errorMessage += " \"Security Question\" "; } if (string.IsNullOrWhiteSpace(this.confirmUserPasswordBox.Password)) { errorMessage += " \"Password\" "; } else if (this.confirmUserPasswordBox.Password != this.userPasswordBox.Password) { MessageBox.Show("Password do not match. Please try again.", "Invalid Password", MessageBoxButton.OK, MessageBoxImage.Error); } if (!(errorMessage == null)) { MessageBox.Show($"{errorMessage} field(s) missing value", "Invalid Fields", MessageBoxButton.OK, MessageBoxImage.Asterisk); } #endregion #region Regular Expression Checks if (!RegexUtilities.IsValidEmail(this.emailTextBox.Text)) { this.emailTextBox.Focus(); } if (!RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text)) { this.phoneTextBox.Focus(); } if (!RegexUtilities.IsValidPassword(this.userPasswordBox.Password)) { this.userPasswordBox.Focus(); } if (this.userPasswordBox.Password != this.confirmUserPasswordBox.Password) { this.lblConfirmPassword.Visibility = Visibility.Visible; this.confirmUserPasswordBox.Focus(); } if (!RegexUtilities.IsValidName(this.firstNameTextBox.Text)) { this.firstNameTextBox.Focus(); } if (!RegexUtilities.IsValidName(this.lastNameTextBox.Text)) { this.lastNameTextBox.Focus(); } if (securityQuestionTextBox.Text == "" || securityQuestionTextBox.Text == null) { this.securityQuestionTextBox.Focus(); } #endregion #region Create a user //If all the data is valid... if (RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text) && RegexUtilities.IsValidName(this.firstNameTextBox.Text) && RegexUtilities.IsValidName(this.lastNameTextBox.Text) && CheckEmail(this.emailTextBox.Text) && RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text) && RegexUtilities.IsValidPassword(this.userPasswordBox.Password) && this.userPasswordBox.Password == this.confirmUserPasswordBox.Password && securityQuestionTextBox.Text != "") { //New instance of encryption class HashManager encrypter = new HashManager(); UserData newUser = new UserData { //Encrypt user data and set to newUser object FirstName = this.firstNameTextBox.Text.ToUpper(), LastName = this.lastNameTextBox.Text.ToUpper(), Email = encrypter.HashTextSHA256(this.emailTextBox.Text), PhoneNumber = encrypter.HashTextSHA256(this.phoneTextBox.Text), Password = encrypter.HashUniqueTextSHA256(this.userPasswordBox.Password), SecurityQuestion = this.securityQuestionComboBox.Text, SecurityQuestionAnswer = encrypter.HashTextSHA256(this.securityQuestionTextBox.Text) }; // SQL Connection String string connectionString = DatabaseConnection.GetConnectionString(); // Open database connection and send that data to the database hashed. DatabaseConnection dbConnection = new DatabaseConnection(connectionString); // checks if account exists. if (dbConnection.CheckAccountExists(newUser.Email, newUser.Password)) { MessageBox.Show("Account already exists with this email", "Account Exists", MessageBoxButton.OK, MessageBoxImage.Asterisk); return; } else { var questionnaire = new QuestionaireWindow(ref newUser); // If you do not press finish, show the dialog again. while (questionnaire.ShowDialog() == false) { questionnaire = new QuestionaireWindow(ref newUser, "Please press finish to confirm your account."); } } try { if (dbConnection.AddUserToDatabase(newUser)) { LoginWindow loginWindow = new LoginWindow(); this.windowSettings.TransitionScreen(loginWindow, this); } } catch (SqlException) { throw new Exception(); } } #endregion }
/// <summary> /// Event handler for GoBackButton click in <see cref="CreateAccountWindow"/>. /// <para>When GoBack is clicked, the window goes back to the /// login screen <see cref="window.CreateAccountWindow"/></para> /// </summary> /// private void GoBackButton_Click(object sender, RoutedEventArgs e) { Window window = new LoginWindow(); this.windowSettings.TransitionScreen(window, this); }