public void ThrowsIfUserPasswordNotSet() { var repository = new InMemoryRepository(); repository.Add(new ChatUser { Name = "SomeUser" }); var service = new MembershipService(repository, new Mock<ICryptoService>().Object); ChatUser user; Assert.False(service.TryAuthenticateUser("SomeUser", "password", out user)); }
public void ThrowsIfUserPasswordDoesNotMatch() { var repository = new InMemoryRepository(); repository.Add(new ChatUser { Name = "SomeUser", Salt = "salt", HashedPassword = "******".ToSha256("salt") }); var service = new MembershipService(repository, new Mock<ICryptoService>().Object); ChatUser user; Assert.False(service.TryAuthenticateUser("SomeUser", "foo", out user)); }
public void ThrowsIfUserDoesNotExist() { var repository = new InMemoryRepository(); var service = new MembershipService(repository, new Mock<ICryptoService>().Object); ChatUser user; Assert.False(service.TryAuthenticateUser("SomeUser", "foo", out user)); }
public void EnsuresStoredPasswordIsSalted() { var crypto = new Mock<ICryptoService>(); crypto.Setup(c => c.CreateSalt()).Returns("salted"); var repository = new InMemoryRepository(); var user = new ChatUser { Name = "foo", HashedPassword = "******" }; repository.Add(user); var service = new MembershipService(repository, crypto.Object); Assert.True(service.TryAuthenticateUser("foo", "passwords", out user)); Assert.Equal("salted", user.Salt); Assert.Equal("9ce70d2ab42c9a9012ed6f80f85ab400ef1483f70e227a42b6d77faea204db26", user.HashedPassword); }
public void DoesNotThrowIfSaltedPasswordsMatch() { var repository = new InMemoryRepository(); repository.Add(new ChatUser { Name = "foo", Salt = "salted", HashedPassword = "******" }); var service = new MembershipService(repository, new Mock<ICryptoService>().Object); ChatUser user; Assert.True(service.TryAuthenticateUser("foo", "password", out user)); }
public void DoesNotThrowIfPasswordsMatch() { var repository = new InMemoryRepository(); repository.Add(new ChatUser { Name = "foo", HashedPassword = "******" }); var service = new MembershipService(repository, new Mock<ICryptoService>().Object); ChatUser user; Assert.True(service.TryAuthenticateUser("foo", "passwords", out user)); }