コード例 #1
0
ファイル: Login.cs プロジェクト: StefanKennedy/Trillionaire
        private void CompleteRegistrationButton_Click(object sender, EventArgs e)
        {
            if (UsernameETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Username");
                return;
            }
            else if (PasswordETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (ReenterPasswordETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Reentered Password");
                return;
            }

            if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text))
            {
                MessageBox.Show("Passwords do not match");
                return;
            }

            UserDatabase userDB = new UserDatabase();

            try
            {
                userDB.AddUser(UsernameETF.Text, PasswordETF.Text);
                userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                return;
            }

            userDB.OutputDatabaseContents();
            userDB.SaveDatabase();
            ClearTextFields();
        }
コード例 #2
0
        // When the Complete Registration Button has been clicked
        private void CompleteRegistrationButton_Click(object sender, EventArgs e)
        {
            // Validation

            if (UsernameETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please enter a Username"); // Show a message box describing the error
                return; // Stop this method
            }
            else if (PasswordETF.Text.Equals("")) // If no password has been entered
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (ReenterPasswordETF.Text.Equals("")) // If the password has not been reentered
            {
                MessageBox.Show("Please reenter a Password");
                return;
            }
            else if (ForgotPasswordQuestionETF.Text.Equals("")) // If the Forgot Password Question has not been entered
            {
                MessageBox.Show("Please enter a Question that will be asked when you have forgotten your password.");
                return;
            }
            else if (ForgotPasswordAnswerETF.Text.Equals("")) // If the Forgot Password Question answer has not been entered
            {
                MessageBox.Show("Please enter the answer to your Forgot Password Question.");
                return;
            }

            if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text)) // If the password and the Reentered Password do not match
            {
                MessageBox.Show("Passwords do not match, please try re-entering them");
                return;
            }

            //Begin Registering the new user

            UserDatabase userDB = new UserDatabase(); // Create a new instance of the User Database. This allows reading and writing of the database

            try
            {
                userDB.AddUser(UsernameETF.Text, PasswordETF.Text); // Attempt to add the new user to the database. Duplicate usernames will be detected here
                userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text.ToLower()); // Attempt to give the user a 'Forgot Password Question' and answer
            }
            catch (Exception exception) // Catch any exception, and perform the following
            {
                MessageBox.Show(exception.Message + ""); // Display a message box describing the error
                return; // Stop this method
            }

            SwitchToLoginView();
            RegistrationCompletedLabel.Visible = true;

            userDB.SaveDatabase(); // Save the database to a file
            ClearTextFields(); // Clear all of the TextBoxes
        }