public void CreatePasswordHash_WhenCalledWithoutSalt_ProperComputedPasswordExpected() { // ARRANGE var sut = new PasswordProvider(); var plainPassword = "******"; // ACT var computedPassword = sut.CreatePasswordHash(plainPassword); // ASSERT computedPassword.Should().NotBeNull(); computedPassword.Hash.Any().Should().BeTrue(); computedPassword.Salt.Any().Should().BeTrue(); }
public void CreatePasswordHash_WhenCalledWithSalt_ProperComputedPasswordExpected() { // ARRANGE var sut = new PasswordProvider(); var salt = Encoding.UTF8.GetBytes("the salt"); var plainPassword = "******"; var hmac = new System.Security.Cryptography.HMACSHA512(salt); var expected = ComputedPassword.Create(hmac.ComputeHash(Encoding.UTF8.GetBytes(plainPassword)), hmac.Key); // ACT var actual = sut.CreatePasswordHash(plainPassword, salt); // ASSERT actual.Should().BeEquivalentTo(expected); }
public void SeedUsers() { var userData = System.IO.File.ReadAllText("SeedData/20181119_UserSeedData.json"); var users = Newtonsoft.Json.JsonConvert.DeserializeObject <List <User> >(userData); var passwordProvider = new PasswordProvider(); users.ForEach(user => { var computedPassword = passwordProvider.CreatePasswordHash("password"); user.PasswordHash = computedPassword.Hash; user.PasswordSalt = computedPassword.Salt; user.Username = user.Username.ToLower(); context.Users.Add(user); }); context.SaveChanges(); }