Exemplo n.º 1
0
        private void ExecuteCreateCmd(object obj)
        {
            IsCreationSucceeded = false;
            if (UserName == string.Empty)
            {
                MessageBox.Show("Please enter user name!");
                return;
            }
            if (DisplayName == string.Empty)
            {
                MessageBox.Show("Please enter display name!");
                return;
            }
            if (Password == string.Empty || Password != ConfirmPassword)
            {
                MessageBox.Show("Please ensure the password!");
                return;
            }
            if (SelectedRole == UserRoles.SuperAdmin)
            {
                MessageBox.Show("Please select the User Role!");
                return;
            }
            User user = new User(UserName, DisplayName, EncryptDecrypt.EncryptString(Password), SelectedRole, 0, DateTime.Today.AddDays(30));

            Workspace.This.Users.Add(user);
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);
            IsCreationSucceeded = true;
        }
        private void _ResetPwdBtn_Click(object sender, RoutedEventArgs e)
        {
            Workspace.This.SelectedUser.ChangePassword("admin");
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);

            ObservableCollection <User> users = Workspace.This.Users;
            User selectedUser = Workspace.This.SelectedUser;

            Workspace.This.Users        = null;
            Workspace.This.Users        = users;
            Workspace.This.SelectedUser = selectedUser;
        }
        private void _ResetLockoutBtn_Click(object sender, RoutedEventArgs e)
        {
            Workspace.This.SelectedUser.ResetLockoutCount();
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);

            ObservableCollection <User> users = Workspace.This.Users;
            User selectedUser = Workspace.This.SelectedUser;

            Workspace.This.Users        = null;
            Workspace.This.Users        = users;
            Workspace.This.SelectedUser = selectedUser;
        }
Exemplo n.º 4
0
 private void _DeleteBtn_Click(object sender, RoutedEventArgs e)
 {
     if (Workspace.This.SelectedUser == null)
     {
         MessageBox.Show("Please select a user account first");
         return;
     }
     if (MessageBox.Show("Are you sure to delete " + Workspace.This.SelectedUser.UserName, "Delete user", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) != MessageBoxResult.Yes)
     {
         return;
     }
     Workspace.This.Users.Remove(Workspace.This.SelectedUser);
     AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);
 }
Exemplo n.º 5
0
        private void _LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_NameBox.Text == null || _NameBox.Text == "")
            {
                MessageBox.Show("Please input user name!");
                return;
            }
            if (_PwdBox.Password == null || _PwdBox.Password == "")
            {
                MessageBox.Show("Please input password");
                return;
            }

            string enteredPasswordHash = EncryptDecrypt.EncryptString(_PwdBox.Password);
            User   user;
            int    i = 0;

            for (; i < Workspace.This.Users.Count; i++)
            {
                user = Workspace.This.Users[i];
                if (string.Equals(user.UserName, _NameBox.Text, StringComparison.OrdinalIgnoreCase))
                {
                    if (user.LockOutCount >= 5)
                    {
                        MessageBox.Show("You are locked out because of too many bad attempts, please contact the administrators for help!");
                        return;
                    }
                    if (user.VerifyPassword(_PwdBox.Password))
                    {
                        break;
                    }
                    else
                    {
                        MessageBox.Show("Incorrect password!");
                        AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);
                        return;
                    }
                }
            }
            if (i >= Workspace.This.Users.Count)
            {
                MessageBox.Show("Invalid user name!");
                return;
            }
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);
            Workspace.This.LoginUser = Workspace.This.Users[i];
            this.DialogResult        = true;
            this.Close();
        }
        private void _ChangeBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_NewPwdBox.Password == string.Empty || _NewPwdBox.Password != _NewPwdConfirmBox.Password)
            {
                MessageBox.Show("Please ensure the new password!");
                return;
            }
            Workspace.This.SelectedUser.ChangePassword(_NewPwdBox.Password);
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);

            ObservableCollection <User> users = Workspace.This.Users;
            User selectedUser = Workspace.This.SelectedUser;

            Workspace.This.Users        = null;
            Workspace.This.Users        = users;
            Workspace.This.SelectedUser = selectedUser;
        }
Exemplo n.º 7
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         Workspace.This.Users = AccountsManagement.LoadFromFile(Workspace.This.UserFilePath);
         Keyboard.Focus(this._NameBox);
     }
     catch (System.IO.FileNotFoundException)
     {
         MessageBox.Show("Accounts data missed! contact administrators to setup the software!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         this.Close();
     }
     catch (System.Runtime.Serialization.SerializationException)
     {
         MessageBox.Show("Accounts data are damaged, please contact administrators!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void _ChangeBtn_Click(object sender, RoutedEventArgs e)
        {
            string originalPwdHash = EncryptDecrypt.EncryptString(_OriginalPwdBox.Password);

            if (originalPwdHash != Workspace.This.LoginUser.PasswordHash)
            {
                MessageBox.Show("Please ensure the original password!");
                return;
            }
            if (_NewPwdBox.Password == string.Empty || _NewPwdBox.Password != _NewPwdConfirmBox.Password)
            {
                MessageBox.Show("Please ensure the new password!");
                return;
            }
            Workspace.This.LoginUser.ChangePassword(_NewPwdBox.Password);
            AccountsManagement.SaveToFile(Workspace.This.Users, Workspace.This.UserFilePath);
            User selectedUser = Workspace.This.SelectedUser;
            ObservableCollection <User> users = Workspace.This.Users;

            Workspace.This.Users        = null;
            Workspace.This.Users        = users;
            Workspace.This.SelectedUser = selectedUser;
            this.Close();
        }