private bool CloseRepository(bool force = false) { bool ret = false; try { if (passwordRepository == null) { return(true); } if (force || PromptSaveChanges()) { passwordRepository = null; passwordSecureString.Clear(); listView.Items.Clear(); reenterPassword = false; ret = true; } } catch (Exception ex) { HandleError(ex); } UpdateControls(); return(ret); }
private bool CreateRepository() { bool ret = false; try { if (!PromptSaveChanges()) { return(false); } PrepareWindow dlg = new PrepareWindow(this, Properties.Resources.TITLE_NEW, keyDirectoryCache); if (dlg.ShowDialog() != true) { return(false); } if (!CloseRepository(true /*force*/)) { return(false); } passwordSecureString = dlg.SecurePassword; passwordRepository = dlg.PasswordRepository; passwordFilename = null; ret = true; } catch (Exception ex) { HandleError(ex); } UpdateControls(); InitThumbnailCacheAsync(); return(ret); }
private void ButtonOK_Click(object sender, RoutedEventArgs e) { try { if (!passwordBox.SecurePassword.IsEqualTo(passwordBoxConfirm.SecurePassword)) { MessageBox.Show($"{Properties.Resources.ERROR_PASSWORD_DOES_NOT_MATCH}", Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (passwordBox.SecurePassword.Length < 4) { MessageBox.Show($"{Properties.Resources.ERROR_PASSWORD_MIN_CHARS}", Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } SecurePassword = passwordBox.SecurePassword; PasswordRepository = new PasswordRepository(); PasswordRepository.Name = textBoxName.Text; PasswordRepository.Description = textBoxDescription.Text; keyDirCache.Set(PasswordRepository.Id, textBoxKeyDirectory.Text); DialogResult = true; Close(); } catch (Exception ex) { MessageBox.Show(string.Format(Properties.Resources.ERROR_OCCURRED_0, ex.Message), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public unit_test_PasswordRepo() { //Setting up In memory dbs. userdb = new SqliteConnection("DataSource=:memory:"); passdb = new SqliteConnection("DataSource=:memory:"); walletdb = new SqliteConnection("DataSource=:memory:"); userdb.Open(); passdb.Open(); walletdb.Open(); var userbuild = new DbContextOptionsBuilder <UserModelContext>() .UseSqlite(userdb).Options; var passbuild = new DbContextOptionsBuilder <PassModelContext>() .UseSqlite(passdb).Options; var walletbuild = new DbContextOptionsBuilder <WalletContext>() .UseSqlite(walletdb).Options; var userContext = new UserModelContext(userbuild); var passContext = new PassModelContext(passbuild); var walletContext = new WalletContext(walletbuild); //Drop and create userContext.Database.EnsureDeleted(); userContext.Database.EnsureCreated(); passContext.Database.EnsureDeleted(); passContext.Database.EnsureCreated(); walletContext.Database.EnsureDeleted(); walletContext.Database.EnsureCreated(); //Seeding data to test on SeedUsers.seedUsers(userContext, passContext, walletContext); _uut = new PasswordRepository(passContext); }
private void LoadLoginInfo() { PasswordRepository password_repos = new PasswordRepository(); string userName = password_repos.GetUsername(); string password = password_repos.GetPassword(); this.Login_TB_UserName.Text = userName; this.Login_TB_Password.Text = password; }
private void SaveInfo() { PasswordRepository password_repos = new PasswordRepository(); password_repos.SaveUserName(this.Login_TB_UserName.Text); if (this.LoginForm_CB_SavePassword.Checked) { password_repos.SavePassword(this.Login_TB_Password.Text); } }
private void LoginForm_CB_SavePassword_CheckedChanged(object sender, EventArgs e) { if (this.LoginForm_CB_SavePassword.Checked) { SaveInfo(); } else { PasswordRepository password_repos = new PasswordRepository(); password_repos.SavePassword(""); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { LoginDetails currentUser; UserDetails user = null; PasswordRepository passwordRepository = new PasswordRepository(); string encryptedPassword = await passwordRepository.GetEncryptedPassword(context.Password); try { var database = LibManagementConnection.GetConnection(); var loginCollection = database.GetCollection <LoginDetails>(CollectionConstant.Login_Collection); var userCollection = database.GetCollection <UserDetails>(CollectionConstant.User_Collection); var logins = await loginCollection.FindAsync(x => x.UserName.ToLower() == context.UserName.ToLower() && x.Password == encryptedPassword); var loginsList = await logins.ToListAsync(); currentUser = loginsList.FirstOrDefault(); var users = await userCollection.FindAsync(x => x.UserName.ToLower() == currentUser.UserName.ToLower()); var usersList = await users.ToListAsync(); user = usersList.FirstOrDefault(); } catch (Exception e) { return; } if (user != null) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("Email", user.Email)); identity.AddClaim(new Claim("FirstName", user.FirstName)); identity.AddClaim(new Claim("LastName", user.LastName)); identity.AddClaim(new Claim("UserName", user.UserName)); identity.AddClaim(new Claim("LoggedOn", DateTime.Now.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, user.RoleType.ToString())); var additionalData = new AuthenticationProperties(new Dictionary <string, string> { { "role", JsonConvert.SerializeObject(user.RoleType.ToString()) } }); var token = new AuthenticationTicket(identity, additionalData); context.Validated(identity); } else { return; } }
private void ButtonOK_Click(object sender, RoutedEventArgs e) { try { if (SecurePassword != null) { if (!SecurePassword.IsEqualTo(passwordBox.SecurePassword)) { MessageBox.Show(Properties.Resources.ERROR_WRONG_PASSWORD, Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } } else { var keydir = textBoxKeyDirectory.Text; var id = textBoxKey.Text; bool oldFormat = false; if (!PasswordRepository.ExistKey(keydir, id)) { if (!PasswordRepository.MigrateKey(keydir, id, passwordBox.SecurePassword)) { MessageBox.Show( string.Format(Properties.Resources.ERROR_KEY_NOT_FOUND_0_1, id, keydir), Title, MessageBoxButton.OK, MessageBoxImage.Information); return; } oldFormat = true; } PasswordRepository = PasswordRepository.Read(repositoryFile, keydir, passwordBox.SecurePassword, oldFormat); // throws exception for wrong password (encoding fails) SecurePassword = passwordBox.SecurePassword; keyDirCache.Set(id, keydir); } DialogResult = true; Close(); } catch (ArgumentException) { MessageBox.Show(Properties.Resources.ERROR_INVALID_FORMAT, Title, MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { MessageBox.Show(Properties.Resources.ERROR_WRONG_PASSWORD, Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public PropertiesWindow(Window owner, string title, KeyDirectoryCache keyDirCache, PasswordRepository repository, string filename) { Owner = owner; Title = title; WindowStartupLocation = WindowStartupLocation.CenterOwner; Topmost = Properties.Settings.Default.Topmost; this.keyDirCache = keyDirCache; this.repository = repository; InitializeComponent(); textBoxName.Text = repository.Name; textBoxDescription.Text = repository.Description; textBoxPasswordFile.Text = filename; textBoxKeyDirectory.Text = keyDirCache.Get(repository.Id); textBoxKey.Text = repository.Id; textBoxName.Focus(); }
public void Login(PasswordRepository password) { }
public Login(PasswordRepository passwordRepository) { PasswordRepository = passwordRepository; }
private bool OpenRepository(string filename, bool silent) { bool ret = false; try { if (!PromptSaveChanges()) { return(false); } if (string.IsNullOrEmpty(filename)) { var opendlg = new Microsoft.Win32.OpenFileDialog() { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Filter = Properties.Resources.FILE_DIALOG_FILTER }; var initDir = Properties.Settings.Default.InitialDirectory.ReplaceSpecialFolder(); if (Directory.Exists(initDir)) { opendlg.InitialDirectory = initDir; } if (opendlg.ShowDialog() != true) { return(false); } filename = opendlg.FileName; Properties.Settings.Default.InitialDirectory = new FileInfo(filename).Directory.FullName; } LoginWindow dlg = new LoginWindow( this, Properties.Resources.VERIFY_PASSWORD, keyDirectoryCache, filename); if (dlg.ShowDialog() == true) { if (!CloseRepository(true)) { return(false); } passwordFilename = filename; passwordRepository = dlg.PasswordRepository; passwordSecureString = dlg.SecurePassword; Properties.Settings.Default.LastUsedRepositoryFile = passwordFilename; foreach (var password in passwordRepository.Passwords) { listView.Items.Add(new PasswordViewItem(password, imageKey16x16)); } SortListView(); InitThumbnailCacheAsync(); textBoxFilter.Focus(); ret = true; } } catch (Exception ex) { HandleError(ex); ret = false; } UpdateControls(); return(ret); }
public UserService(IUserRepository userRepository, PasswordRepository passwordRepository, ISettingPepository settingPepository) { _userRepository = userRepository; _PasswordRepository = passwordRepository; _settingPepository = settingPepository; }
public UnitOfWork(AppDbContext context) { _context = context; Users = new UserRepository(_context); Passwords = new PasswordRepository(_context); }