Skip to content
Browse files

fixing the change password changes that were merged, according to oth…

…er changes that have happened since then (like adding the new has algorithm) (fixes #356)
  • Loading branch information...
1 parent c88823f commit b816dbf3b920981ea63b5c9c38f613a4951ffbef @half-ogre half-ogre committed Jan 28, 2012
Showing with 6 additions and 8 deletions.
  1. +3 −5 Facts/Services/UsersServiceFacts.cs
  2. +1 −1 Website/Services/IUserService.cs
  3. +2 −2 Website/Services/UserService.cs
View
8 Facts/Services/UsersServiceFacts.cs
@@ -603,13 +603,12 @@ public void FindsUsersByUserName()
var user = new User { Username = "theUsername", HashedPassword = "thePassword", EmailAddress = "test@example.com" };
var userRepository = new Mock<IEntityRepository<User>>();
userRepository.Setup(r => r.GetAll()).Returns(new[] { user }.AsQueryable());
-
var crypto = new Mock<ICryptographyService>();
crypto.Setup(c => c.ValidateSaltedHash(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(true);
-
var service = CreateUsersService(cryptoSvc: crypto, userRepo: userRepository);
- var foundByUserName = service.FindByUsernameOrEmailAddressAndPassword("theUsername", "thePassword");
+ var foundByUserName = service.FindByUsernameAndPassword("theUsername", "thePassword");
+
Assert.NotNull(foundByUserName);
Assert.Same(user, foundByUserName);
}
@@ -620,13 +619,12 @@ public void WillNotFindsUsersByEmailAddress()
var user = new User { Username = "theUsername", HashedPassword = "thePassword", EmailAddress = "test@example.com" };
var userRepository = new Mock<IEntityRepository<User>>();
userRepository.Setup(r => r.GetAll()).Returns(new[] { user }.AsQueryable());
-
var crypto = new Mock<ICryptographyService>();
crypto.Setup(c => c.ValidateSaltedHash(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(true);
-
var service = CreateUsersService(cryptoSvc: crypto, userRepo: userRepository);
var foundByEmailAddress = service.FindByUsernameAndPassword("test@example.com", "thePassword");
+
Assert.Null(foundByEmailAddress);
}
}
View
2 Website/Services/IUserService.cs
@@ -24,7 +24,7 @@ public interface IUserService
bool ConfirmEmailAddress(User user, string token);
- bool ChangePassword(string usernameOrEmail, string oldPassword, string newPassword);
+ bool ChangePassword(string username, string oldPassword, string newPassword);
User GeneratePasswordResetToken(string usernameOrEmail, int tokenExpirationMinutes);
View
4 Website/Services/UserService.cs
@@ -126,7 +126,7 @@ public virtual User FindByUsernameAndPassword(string username, string password)
if (user == null)
return null;
- if (!cryptoSvc.ValidateSaltedHash(user.HashedPassword, password))
+ if (!cryptoSvc.ValidateSaltedHash(user.HashedPassword, password, user.PasswordHashAlgorithm))
return null;
return user;
@@ -170,7 +170,7 @@ public string GenerateApiKey(string username)
return newApiKey.ToString();
}
- public bool ChangePassword(string usernameOrEmail, string oldPassword, string newPassword)
+ public bool ChangePassword(string username, string oldPassword, string newPassword)
{
// Review: If the old password is hashed using something other than PBKDF2, we end up making an extra db call that changes the old hash password.
// This operation is rare enough that I'm not inclined to change it.

0 comments on commit b816dbf

Please sign in to comment.
Something went wrong with that request. Please try again.