Search in sources :

Example 1 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class ChangePasswordAdminCommandTest method shouldReportWhenSaveFailed.

@Test
public void shouldReportWhenSaveFailed() {
    // given
    CommandSender sender = mock(CommandSender.class);
    String player = "my_user12";
    String password = "passPass";
    given(playerCache.isAuthenticated(player)).willReturn(true);
    given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
    HashedPassword hashedPassword = mock(HashedPassword.class);
    given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
    given(dataSource.updatePassword(player, hashedPassword)).willReturn(false);
    // when
    command.executeCommand(sender, Arrays.asList(player, password));
    runOptionallyAsyncTask(bukkitService);
    // then
    verify(validationService).validatePassword(password, player);
    verify(service).send(sender, MessageKey.ERROR);
    verify(passwordSecurity).computeHash(password, player);
    verify(dataSource).updatePassword(player, hashedPassword);
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 2 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class NewAPI 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();
    HashedPassword result = passwordSecurity.computeHash(password, name);
    if (isRegistered(name)) {
        return false;
    }
    PlayerAuth auth = PlayerAuth.builder().name(name).password(result).realName(playerName).build();
    return dataSource.saveAuth(auth);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Example 3 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class EmailRegisterExecutorProviderTest method shouldCreatePlayerAuth.

@Test
public void shouldCreatePlayerAuth() {
    // given
    given(commonService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(12);
    given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
    Player player = mock(Player.class);
    TestHelper.mockPlayerIp(player, "123.45.67.89");
    given(player.getName()).willReturn("Veronica");
    World world = mock(World.class);
    given(world.getName()).willReturn("someWorld");
    given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
    EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
    // when
    PlayerAuth auth = executor.buildPlayerAuth(params);
    // then
    assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
    assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
    assertThat(auth.getPassword().getHash(), stringWithLength(12));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Location(org.bukkit.Location) Test(org.junit.Test)

Example 4 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class PlayerAuth method deserialize.

/**
     * Method to deserialize PlayerAuth
     * 
     * @param str String
     */
public void deserialize(String str) {
    String[] args = str.split(";");
    this.nickname = args[0];
    this.realName = args[1];
    this.ip = args[2];
    this.email = args[3];
    this.password = new HashedPassword(args[4], args[5]);
    this.groupId = Integer.parseInt(args[6]);
    this.lastLogin = Long.parseLong(args[7]);
    this.world = args[8];
    this.x = Double.parseDouble(args[9]);
    this.y = Double.parseDouble(args[10]);
    this.z = Double.parseDouble(args[11]);
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Example 5 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class PlayerAuthViewer method displayAuthToSender.

/**
 * Outputs the PlayerAuth information to the given sender.
 *
 * @param auth the PlayerAuth to display
 * @param sender the sender to send the messages to
 */
private void displayAuthToSender(PlayerAuth auth, CommandSender sender) {
    sender.sendMessage(ChatColor.BLUE + "[AuthMe] Player " + auth.getNickname() + " / " + auth.getRealName());
    sender.sendMessage("Email: " + auth.getEmail() + ". IP: " + auth.getLastIp() + ". Group: " + auth.getGroupId());
    sender.sendMessage("Quit location: " + formatLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld()));
    sender.sendMessage("Last login: " + formatDate(auth.getLastLogin()));
    sender.sendMessage("Registration: " + formatDate(auth.getRegistrationDate()) + " with IP " + auth.getRegistrationIp());
    HashedPassword hashedPass = auth.getPassword();
    sender.sendMessage("Hash / salt (partial): '" + safeSubstring(hashedPass.getHash(), 6) + "' / '" + safeSubstring(hashedPass.getSalt(), 4) + "'");
    sender.sendMessage("TOTP code (partial): '" + safeSubstring(auth.getTotpKey(), 3) + "'");
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

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