private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     if (new ValidationClass().CheckIfNotEmpty(OldPasswordBox.Text, NewPasswordBox.Text, ConfirmNewPasswordBox.Text))
     {
         if (NewPasswordBox.Text == ConfirmNewPasswordBox.Text)
         {
             PasskeeperModelContext db = new PasskeeperModelContext();
             try
             {
                 var users = from u in db.Users
                             select u;
                 var findUser = db.Users.FirstOrDefault(u => u.UserId == MainWindow.LoggedUser);
                 if (PasswordProtect.ValidatePassword(OldPasswordBox.Text, findUser.MasterPassword))
                 {
                     findUser.MasterPassword = PasswordProtect.CreateHash(NewPasswordBox.Text);
                     db.SaveChanges();
                     DialogResult = true;
                 }
                 else
                 {
                     MessageBox.Show("Old password is incorrect!");
                 }
             }
             catch (Exception err)
             {
                 MessageBox.Show(err.ToString());
             }
         }
         else
         {
             MessageBox.Show("New passwords do not match!");
         }
     }
 }
Esempio n. 2
0
 private void EnterButton_Click(object sender, RoutedEventArgs e)
 {
     if (new ValidationClass().CheckIfNotEmpty(LoginBox.Text, PasswordBox.Password))
     {
         PasskeeperModelContext db = new PasskeeperModelContext();
         try
         {
             var findUser = db.Users.FirstOrDefault(u => u.Username == LoginBox.Text);
             if (findUser != null && PasswordProtect.ValidatePassword(PasswordBox.Password, findUser.MasterPassword))
             {
                 MainWindow.LoggedUser = findUser.UserId;
                 MainWindow.Secret     = findUser.Username;
                 DialogResult          = true;
             }
             else
             {
                 MessageBox.Show("Wrong login or password!");
                 PasswordBox.Password = "";
                 LoginBox.Focus();
             }
         }
         catch (Exception err)
         {
             MessageBox.Show(err.ToString());
         }
     }
     else
     {
         MessageBox.Show("Please populate all fields!");
     }
 }