public void LengthRoundTrip(PasswordHasherAlgorithms algorithm, int saltSize, int expectedLength) { // Arrange var hasher = new PasswordHasher(BuildOptions(algorithm, saltSize)); // Act & assert - success case var hashedPassword = hasher.HashPassword("password 1"); Assert.Equal(expectedLength, hashedPassword.Length); }
public void OptionsRoundTrip(PasswordHasherAlgorithms algorithm, int expectedSize) { // Arrange var options = new PasswordHasherOptions(algorithm); // Act & assert - success case Assert.Equal(expectedSize, options.HashSize); // Arrange options.HashAlgorithm = PasswordHasherAlgorithms.SHA1; options.SaltSize = expectedSize; options.HashAlgorithm = algorithm; // Act & assert - failure case Assert.Equal(expectedSize, options.HashSize); }
public void HashRoundTrip(PasswordHasherAlgorithms algorithm) { // Arrange var hasher = new PasswordHasher(BuildOptions(algorithm)); // Act & assert - success case var hashedPassword = hasher.HashPassword("password 1"); var successResult = hasher.VerifyHashedPassword(hashedPassword, "password 1"); Assert.True(successResult); // Act & assert - failure case var failedResult = hasher.VerifyHashedPassword(hashedPassword, "password 2"); Assert.False(failedResult); }
public static IOptions <PasswordHasherOptions> BuildOptions(PasswordHasherAlgorithms algorithm, int?saltSize = null, int?iterations = null) { var options = new PasswordHasherOptions(algorithm, saltSize, iterations); return(Options.Create(options)); }