示例#1
0
        private void UpdatePasword(object sender, RoutedEventArgs e)
        {
            db = new FCS_DBModel();
            string password       = Password.Password.ToString();
            string verifiedPW     = VerifyPassword.Password.ToString();
            string hashedPassword = PasswordHashing.GetHashString(password);

            if (password.Length < 5)
            {
                MessageBox.Show("Please pick a longer password (Minimum length of 5)");
            }
            else if (password != verifiedPW)
            {
                MessageBox.Show("Passwords do not match!");
            }
            else
            {
                try {
                    var staff = (from p in db.Staff
                                 where p.StaffID == StaffID
                                 select p).First();
                    staff.StaffPassword = hashedPassword;
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("Something went wrong. Please try again.");
                }
                this.Close();
            }
        }
        private void CreateAccount(object sender, RoutedEventArgs e)
        {
            Models.FCS_DBModel db   = new Models.FCS_DBModel();
            string             Role = UserRole.SelectedValue.ToString();

            string password       = Password.Password.ToString();
            string verifiedPW     = VerifyPassword.Password.ToString();
            string hashedPassword = PasswordHashing.GetHashString(password);

            int usernameVerify = (from uv in db.Staff
                                  where uv.StaffUserName == UserName
                                  select uv).Count();

            if (Role == "No Access")
            {
                if (FirstName == null || FirstName == "" || LastName == null || LastName == "" || StaffTitle == null || StaffTitle == "")
                {
                    MessageBox.Show("Please check the data entered.");
                }
                else
                {
                    Models.Staff account = new Models.Staff();
                    account.StaffFirstName = FirstName;
                    account.StaffLastName  = LastName;
                    account.StaffTitle     = StaffTitle;
                    account.StaffUserName  = UserName;
                    account.StaffPassword  = hashedPassword;
                    account.StaffDBRole    = Role;
                    db.Staff.Add(account);
                    db.SaveChanges();
                    this.Close();
                }
            }
            else
            {
                if (password.Length < 5)
                {
                    MessageBox.Show("Please pick a longer password (Minimum length of 5)");
                }
                else if (password != verifiedPW)
                {
                    MessageBox.Show("Passwords do not match!");
                }
                else if (UserName == null || UserName == "" || FirstName == null || FirstName == "" ||
                         LastName == null || LastName == "" || StaffTitle == null || StaffTitle == "")
                {
                    MessageBox.Show("Please check the data entered. A required field is missing.");
                }
                else if (UserName.Contains(" "))
                {
                    MessageBox.Show("User name cannot contain spaces");
                }
                else if (usernameVerify != 0)
                {
                    MessageBox.Show("That username selected is already taken");
                }
                else
                {
                    Models.Staff account = new Models.Staff();
                    account.StaffFirstName = FirstName;
                    account.StaffLastName  = LastName;
                    account.StaffTitle     = StaffTitle;
                    account.StaffUserName  = UserName;
                    account.StaffPassword  = hashedPassword;
                    account.StaffDBRole    = Role;
                    db.Staff.Add(account);
                    db.SaveChanges();
                    this.Close();
                }
            }
        }