Ejemplo n.º 1
0
        /// <summary>
        /// Closes the window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            logonScreen logonScreen = new logonScreen();

            logonScreen.Show();
            Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides data validation and creates an account
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateAnAccount_Click(object sender, RoutedEventArgs e)
        {
            string firstName, lastName, username, password, birthday, question, answer;

            firstName = textBoxFirstName.Text;
            lastName  = textBoxLastName.Text;
            username  = textBoxUsername.Text;
            password  = textBoxPassword.Password;
            birthday  = textBoxBirthday.Text;
            question  = comboBoxQuestion.Text;
            answer    = textBoxAnswer.Text;

            switch (UserAuthentication.ValidateRegisterData(firstName, lastName, username, password, birthday, question, answer))
            {
            case 1:
                MessageBox.Show("You need to fill in a form to create an account.", "Wrong register data", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;

            case 2:
                MessageBox.Show("Your username must contain at least 3 characters.", "Your username is too short", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;

            case 3:
                MessageBox.Show("Your password should be at least 8 characters long, composed of both lowercase and uppercase letters and digits.",
                                "Your password is too weak", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;

            case 4:
                MessageBox.Show("Your password can not contain white spaces.", "Illegal characters", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;

            case 5:
                MessageBox.Show("Your birthday date should be like: 15-05-1990", "Wrong birthday format", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;


            case 0:
            {
                User user = new User(firstName, lastName, username, password, birthday, question, answer, "");
                switch (UserAuthentication.Register(user))
                {
                case 0:
                {
                    MessageBox.Show("Your account has been successfully created. You can log in with your credentials.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    logonScreen logonScreen = new logonScreen();
                    logonScreen.Show();
                    Close();
                }
                break;

                case 1:
                {
                    MessageBox.Show("Account creation failed.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

                case 2:
                {
                    MessageBox.Show("This username is already used.", "Invalid username", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                break;
                }
            }
            break;
            }
        }