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!");
         }
     }
 }
Example #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!");
     }
 }
Example #3
0
 public void dataLoad()
 {
     context = new PasskeeperModelContext();
     try
     {
         context.PasswordSets.Where(p => p.UserUserId == LoggedUser && p.Status == "active").Load();
         this.DataContext = context.PasswordSets.Local;
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
Example #4
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (new ValidationClass().CheckIfNotEmpty(LoginBox.Text, PasswordBox.Text, RepeatPassBox.Text, EmailBox.Text))
            {
                if (RepeatPassBox.Text == PasswordBox.Text)
                {
                    PasskeeperModelContext context = new PasskeeperModelContext();
                    var user = new User();
                    user.Username       = LoginBox.Text;
                    user.MasterPassword = PasswordProtect.CreateHash(PasswordBox.Text);
                    user.Email          = EmailBox.Text;
                    user.DateCreated    = DateTime.Now;
                    user.Status         = "active";

                    try
                    {
                        var users = from u in context.Users
                                    select u;
                        var duplicate = context.Users.FirstOrDefault(u => u.Username == user.Username);

                        if (duplicate != null)
                        {
                            MessageBox.Show("Such username already exists! Please make another username!");
                        }
                        else
                        {
                            context.Users.Add(user);
                            context.SaveChanges();
                            MessageBox.Show("User was added successfully!");
                            DialogResult = true;
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("Passwords do not match!");
                }
            }
            else
            {
                MessageBox.Show("Please populate all fields!");
            }
        }
Example #5
0
 private void ResetButton_Click(object sender, RoutedEventArgs e)
 {
     if (new ValidationClass().CheckIfNotEmpty(EmailBox.Text))
     {
         PasskeeperModelContext db = new PasskeeperModelContext();
         try
         {
             var users = from u in db.Users
                         select u;
             var findUser = db.Users.FirstOrDefault(u => u.Email == EmailBox.Text);
             if (findUser != null)
             {
                 byte[] ba = new byte[8];
                 new RNGCryptoServiceProvider().GetBytes(ba);
                 var    hexString   = BitConverter.ToString(ba);
                 string newPassword = hexString.Replace("-", "");
                 findUser.MasterPassword = PasswordProtect.CreateHash(newPassword);
                 db.SaveChanges();
                 new EmailingClass().SendEmail(EmailBox.Text, "Your password for PassKeeper is reset", newPassword);
                 DialogResult = true;
             }
             else
             {
                 MessageBox.Show("This e-mail is not registered!");
                 EmailBox.Focus();
             }
         }
         catch (Exception err)
         {
             MessageBox.Show(err.ToString());
         }
     }
     else
     {
         MessageBox.Show("Please populate all fields!");
     }
 }