コード例 #1
0
        private void NameAndPassword_TextChanged(object sender, EventArgs e)
        {
            lbl_Info.ResetText();
            lbl_Info.ForeColor = Color.DarkRed;
            string modifiedUsername = txtBxName.Text.Trim();
            string modifiedPassword = txtBxPassword.Text.Trim();

            if (modifiedUsername != thisUser.Username ||
                modifiedPassword != thisUser.Password)
            {
                if (modifiedPassword.Length < 6 ||
                    modifiedUsername.Length < 6)
                {
                    lbl_Info.Text = "Username or Password must be at least 6 characters long.";
                    return;
                }
                //input checking
                if (acctReader.AccountExists(modifiedUsername) && modifiedUsername != thisUser.Username)
                {
                    lbl_Info.Text = "That username is already used.";
                }
                else
                {
                    userHasBeenModified = true;
                    lbl_Info.Text       = "User has been modified.";
                    lbl_Info.ForeColor  = Color.Yellow;
                }
            }
            else
            {
                userHasBeenModified = false;
                lbl_Info.Text       = "";
            }
        }
コード例 #2
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            string username     = txtBxName.Text.Trim();
            string password     = txtBxPassword.Text.Trim();
            string passwordConf = txtBxPasswordConf.Text.Trim();

            if (username == "" ||
                password == "" ||
                username.Length < 6 ||
                password.Length < 6)
            {
                lbl_Info.Text = "Username and password must be at least 6 characters long.";
            }
            else if (acctReader.AccountExists(username))
            {
                lbl_Info.Text = "Username is already used. Please enter another.";
            }
            else if (password != passwordConf)
            {
                lbl_Info.Text = "Passwords don't match.";
            }
            else
            {
                if (chkBxIsAdmin.Checked)
                {
                    acctReader.WriteAdminAccount(username, password);
                    lbl_Info.ForeColor = Color.Green;
                    lbl_Info.Text      = "New admin successfully added!";
                    MessageBox.Show("New admin successfully added!", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    this.newAdmin = acctReader.GetAdminAccount(username, password);
                    this.Close();
                }
                else
                {
                    acctReader.WriteUserAccount(username, password);
                    lbl_Info.ForeColor = Color.Green;
                    lbl_Info.Text      = "New user successfully added!";
                    MessageBox.Show("New user successfully added!", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    this.newUser = acctReader.GetUserAccount(username, password);
                    this.Close();
                }
            }
        }
コード例 #3
0
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            string userName = txtBxUser.Text.Trim();
            string passWord = txtBxPass.Text.Trim();
            string confPW   = txtBxConfPw.Text.Trim();

            //Check first if input is valid
            if (!ValidateInput(userName, passWord))
            {
                return;
            }

            //Sign In
            if (btnSignIn.Text == "Sign In")
            {
                //Verify login details
                if (acctAcc.IsValidAccount(userName, passWord))
                {
                    //distinguish between user and admin account,
                    //start with user account first

                    if (acctAcc.IsAdminAccount(userName, passWord))
                    {
                        //get admin account
                        var adminAccount = acctAcc.GetAdminAccount(userName, passWord);

                        MessageBox.Show("Admin verified, welcome " + adminAccount.Username + '!', "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //admin window here
                        User_Interface.AdminUI ui_admin = new User_Interface.AdminUI(this, adminAccount);
                        txtBxUser.ResetText();
                        txtBxPass.ResetText();
                        this.Hide();
                        ui_admin.Show();
                    }
                    else
                    {
                        //get user account
                        var userAccount = acctAcc.GetUserAccount(userName, passWord);

                        MessageBox.Show("Login success!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //Instantiate the MainMenu
                        MainWindowUI ui_main = new MainWindowUI(this, userAccount);
                        txtBxUser.ResetText();
                        txtBxPass.ResetText();
                        this.Hide();
                        ui_main.Show();
                    }
                }
                //If no match, inform user
                else
                {
                    MessageBox.Show("Incorrect username or password entered.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtBxPass.Focus();
                    txtBxPass.SelectAll();
                }
            }
            //Sign Up
            else
            {
                //Verify login details
                if (acctAcc.AccountExists(userName))
                {
                    MessageBox.Show("Username is already used. Please enter a new one.", "Sign Up", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBxUser.Focus();
                    txtBxUser.SelectAll();
                    return;
                }
                else if (confPW != passWord)
                {
                    MessageBox.Show("Passwords don't match.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtBxConfPw.ResetText();
                    txtBxPass.Focus();
                    txtBxPass.SelectAll();
                    return;
                }
                //If no match, create account and inform user
                else
                {
                    acctAcc.WriteUserAccount(userName, passWord);
                    MessageBox.Show("Account creation success!", "Sign Up", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBxPass.ResetText();
                    txtBxPass.Focus();

                    btnSignIn.Text    = "Sign In";
                    lblSign.Text      = "Don't have an account?";
                    lnkLblSignUp.Text = "Sign up now.";
                    lblConfPw.Enabled = false;
                    lblConfPw.Visible = false;
                    txtBxConfPw.ResetText();
                    txtBxConfPw.Enabled = false;
                    txtBxConfPw.Visible = false;
                }
            }
        }
コード例 #4
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            string input = txtBxInput.Text.Trim();

            //password entering phase
            if (lbl_Input.Text == "Password: "******"Password must be at least 6 characters long.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else if (input != adminUser.Password)
                {
                    lbl_Info.Text      = "Incorrect password entered.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else
                {
                    lbl_Info.Text      = "Enter your new username.";
                    lbl_Input.Text     = "New username: "******"Username must be at least 6 characters long.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else if (acctReader.AccountExists(input))
                {
                    lbl_Info.Text      = "Username is already used. Please enter another.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else
                {
                    lbl_Info.Text      = "Enter your new username.";
                    lbl_Info.ForeColor = Color.Black;

                    //confirm username change
                    DialogResult response = MessageBox.Show("Change username?", "Reset Username",
                                                            MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

                    if (response == DialogResult.Yes)
                    {
                        //change username
                        if (acctReader.UpdateAccount(adminUser.Id, input, adminUser.Password))
                        {
                            adminUser = acctReader.GetAdminAccount(input, adminUser.Password);
                            MessageBox.Show("Username changed!", "Reset Username", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                            lbl_Info.Text      = "Username successfully changed!";
                            lbl_Info.ForeColor = Color.Green;
                            usernameChanged    = true;

                            this.Close();
                        }
                        else
                        {
                            Trace.WriteLine("Failed to update new username: "******", with password: "******", and ID: " + adminUser.Id);
                            MessageBox.Show("Failed to change username.", "Reset Username", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            lbl_Info.Text      = "Enter your new username.";
                            lbl_Info.ForeColor = Color.Black;
                        }
                    }
                }
            }
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="username"></param>
 /// <returns>
 /// true if username exists in database, false otherwise
 /// </returns>
 public bool IsValidUsername(string username)
 {
     return(accountManager.AccountExists(username));
 }