public string GetAccountPassword(int accountIndex) { Database.Account account = _dbProfile.Accounts[accountIndex]; // If encrypted password is null the password was generated with the program so we just re-generate it // If it isn't null the password was given by the user so we need to decrypt it return((account.EncryptedPassword == null) ? Crypto.GenerateHashWithSeed(account.ServiceName + account.Username, _phraseHash) : Crypto.DecryptStringAES(account.EncryptedPassword, _phraseHash)); }
public Database.Account AddAccount(string servicename, string username, string password) { // If password was generated by the program we don't need to save it, just the variables we can use to regenerate it var encryptedpassword = (password == null) ? null : Crypto.EncryptStringAES(password, _phraseHash); var newAccount = new Database.Account(servicename, username, encryptedpassword); // Create account object // Make sure profile does not already have an account with that name if (_dbProfile.Accounts.Any(a => (a.Username == username) && (a.ServiceName == servicename))) { return(null); } // Add account to profile _dbProfile.Accounts.Add(newAccount); // Add account to profile objects list Database.SaveProfile(_dbProfile); // Save account in database return(newAccount); }
private void addAccountButton_Click(object sender, EventArgs e) { AddAccountForm newAccountForm = new AddAccountForm(ActiveProfile); newAccountForm.StartPosition = FormStartPosition.CenterParent; newAccountForm.ShowDialog(); string service = newAccountForm.Service; string username = newAccountForm.Username; string password = newAccountForm.Password; if (string.IsNullOrWhiteSpace(service) || string.IsNullOrWhiteSpace(username)) { return; } Database.Account newAccount = ActiveProfile.AddAccount(service, username, password); if (newAccount == null) { MessageBox.Show("You already have an account for that service and username in this profile."); return; } DisplayAccount(service, username); }