Search in sources :

Example 6 with HashedPassword

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"));
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 7 with HashedPassword

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"));
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 8 with HashedPassword

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));
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 9 with HashedPassword

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);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Example 10 with HashedPassword

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);
}
Also used : Player(org.bukkit.entity.Player) ValidationService(fr.xephi.authme.service.ValidationService) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Aggregations

HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)55 Test (org.junit.Test)35 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)22 Player (org.bukkit.entity.Player)14 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)9 CommandSender (org.bukkit.command.CommandSender)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PasswordEncryptionEvent (fr.xephi.authme.events.PasswordEncryptionEvent)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ValidationService (fr.xephi.authme.service.ValidationService)2 Connection (java.sql.Connection)2 PotionEffect (org.bukkit.potion.PotionEffect)2 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)1 EncryptionMethod (fr.xephi.authme.security.crypts.EncryptionMethod)1 Joomla (fr.xephi.authme.security.crypts.Joomla)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1