use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceIntegrationTest method shouldReturnPasswordWithEmptySaltColumn.
@Test
public void shouldReturnPasswordWithEmptySaltColumn() {
// given
DataSource dataSource = getDataSource("");
// when
HashedPassword bobbyPassword = dataSource.getPassword("bobby");
HashedPassword invalidPassword = dataSource.getPassword("doesNotExist");
HashedPassword userPassword = dataSource.getPassword("user");
// then
assertThat(bobbyPassword, equalToHash("$SHA$11aa0706173d7272$dbba966"));
assertThat(invalidPassword, nullValue());
assertThat(userPassword, equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b"));
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceIntegrationTest method shouldUpdatePasswordWithNoSalt.
@Test
public void shouldUpdatePasswordWithNoSalt() {
// given
DataSource dataSource = getDataSource("");
HashedPassword newHash = new HashedPassword("new_hash", "1241");
// when
boolean response1 = dataSource.updatePassword("user", newHash);
boolean response2 = dataSource.updatePassword("non-existent-name", new HashedPassword("asdfasdf", "a1f34ec"));
// then
assertThat(response1, equalTo(true));
// no record modified
assertThat(response2, equalTo(false));
assertThat(dataSource.getPassword("user"), equalToHash("new_hash"));
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceIntegrationTest method shouldUpdatePassword.
@Test
public void shouldUpdatePassword() {
// given
DataSource dataSource = getDataSource();
HashedPassword newHash = new HashedPassword("new_hash");
// when
boolean response1 = dataSource.updatePassword("user", newHash);
boolean response2 = dataSource.updatePassword("non-existent-name", new HashedPassword("sd"));
// then
assertThat(response1, equalTo(true));
// no record modified
assertThat(response2, equalTo(false));
assertThat(dataSource.getPassword("user"), equalToHash(newHash));
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AuthMeApi method registerPlayer.
/**
* Register an OFFLINE/ONLINE player with the given password.
*
* @param playerName The player to register
* @param password The password to register the player with
*
* @return true if the player was registered successfully
*/
public boolean registerPlayer(String playerName, String password) {
String name = playerName.toLowerCase();
if (isRegistered(name)) {
return false;
}
HashedPassword result = passwordSecurity.computeHash(password, name);
PlayerAuth auth = PlayerAuth.builder().name(name).password(result).realName(playerName).registrationDate(System.currentTimeMillis()).build();
return dataSource.saveAuth(auth);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class EmailSetPasswordCommandTest method shouldChangePassword.
@Test
public void shouldChangePassword() {
// given
Player player = mock(Player.class);
String name = "Jerry";
given(player.getName()).willReturn(name);
given(recoveryService.canChangePassword(player)).willReturn(true);
HashedPassword hashedPassword = passwordSecurity.computeHash("abc123", name);
given(passwordSecurity.computeHash("abc123", name)).willReturn(hashedPassword);
given(validationService.validatePassword("abc123", name)).willReturn(new ValidationService.ValidationResult());
// when
command.runCommand(player, Collections.singletonList("abc123"));
// then
verify(validationService).validatePassword("abc123", name);
verify(dataSource).updatePassword(name, hashedPassword);
verify(recoveryService).removeFromSuccessfulRecovery(player);
verify(commonService).send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
}
Aggregations