private static bool ValidateUser(Account account, HashedPWAccount savedUser) { if (savedUser == null) { return(false); } var salt = savedUser.Salt; var hash = SHA256Utility.ComputeHash(account.Password + salt); return(hash == savedUser.Hash); }
/// <summary> /// Adds and Account. Doesn't catch exceptions if Username already exists /// </summary> /// <param name="account"></param> /// <param name="saltLength"></param> public static void AddAccount(this DbSet <HashedPWAccount> dbset, Account account, int saltLength = 512) { var salt = Salt.GenerateSalt(saltLength); HashedPWAccount hashedPWAccount = new HashedPWAccount { User = account.User, Salt = salt, Hash = SHA256Utility.ComputeHash(account.Password + salt) }; dbset.Add(hashedPWAccount); }