Exemplo n.º 1
0
        private void SubmitCommandExecute(object obj)
        {
            try
            {
                string password = (obj as PasswordBox).Password;

                if (!string.IsNullOrEmpty(UserName) && passwordValidation.PasswordOk(password))
                {
                    string hash = SecurePasswordHasher.Hash(password);
                    User.Username = UserName;
                    User.Password = hash;
                    service.AddUser(User);

                    MainWindow employeeView = new MainWindow();
                    loginScreen.Close();
                    employeeView.Show();
                }
                else
                {
                    MessageBox.Show("Wrong usename or password! You must have at least 6 characters with 2 uppercase letters! ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private void SubmitCommandExecute(object obj)
 {
     try
     {
         string password = (obj as PasswordBox).Password;
         if (UserName.Equals("Admin") && password.Equals("Admin123"))
         {
             if (!users.IsUser("Admin"))
             {
                 User.Username       = UserName;
                 User.Password       = password;
                 User.NameAndSurname = "Administrator";
                 users.AddUser(User);
                 AdminView admin = new AdminView();
                 loginScreen.Close();
                 admin.ShowDialog();
             }
             else
             {
                 AdminView admin = new AdminView();
                 loginScreen.Close();
                 admin.ShowDialog();
             }
         }
         else if (users.IsUser(UserName))
         {
             User = users.FindUser(UserName);
             if (SecurePasswordHasher.Verify(password, User.Password))
             {
                 UserView userWindow = new UserView(User);
                 loginScreen.Close();
                 userWindow.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Wrong password!");
             }
         }
         else
         {
             if (PasswordValidation.PasswordOk(password))
             {
                 NameAndSurnameView nameAndSurnameView = new NameAndSurnameView(UserName, password);
                 loginScreen.Close();
                 nameAndSurnameView.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Password must contain at least 5 characters!");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }