ChangeUserPassword() public method

public ChangeUserPassword ( JabbR.Models.ChatUser user, string oldPassword, string newPassword ) : void
user JabbR.Models.ChatUser
oldPassword string
newPassword string
return void
コード例 #1
0
            public void ThrowsUserPasswordDoesNotMatchOldPassword()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "Test",
                    Salt = "salt",
                    HashedPassword = "******".ToSha256("salt")
                };
                repository.Add(user);
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                Assert.Throws<InvalidOperationException>(() => service.ChangeUserPassword(user, "passwor", "foo"));
            }
コード例 #2
0
            public void UpatesUserPassword()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "Test",
                    Salt = "pepper",
                    HashedPassword = "******".ToSha256("pepper")
                };
                repository.Add(user);
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                service.ChangeUserPassword(user, "password", "password2");

                Assert.Equal("password2".ToSha256("pepper"), user.HashedPassword);
            }
コード例 #3
0
            public void EnsuresSaltedPassword()
            {
                var crypto = new Mock<ICryptoService>();
                crypto.Setup(c => c.CreateSalt()).Returns("salt");
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "Test",
                    Salt = null,
                    HashedPassword = "******".ToSha256(null)
                };
                repository.Add(user);
                var service = new MembershipService(repository, crypto.Object);

                service.ChangeUserPassword(user, "password", "password");

                Assert.Equal("salt", user.Salt);
                Assert.Equal("password".ToSha256("salt"), user.HashedPassword);
            }