Search in sources :

Example 11 with HashedPassword

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

the class RegisterAdminCommandTest method shouldRegisterOfflinePlayer.

@Test
public void shouldRegisterOfflinePlayer() {
    // given
    String user = "someone";
    String password = "Al1O3P49S5%";
    given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
    given(dataSource.isAuthAvailable(user)).willReturn(false);
    given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(true);
    HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048");
    given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
    given(bukkitService.getPlayerExact(user)).willReturn(null);
    CommandSender sender = mock(CommandSender.class);
    setBukkitServiceToRunTaskOptionallyAsync(bukkitService);
    // when
    command.executeCommand(sender, Arrays.asList(user, password));
    // then
    verify(validationService).validatePassword(password, user);
    verify(commandService).send(sender, MessageKey.REGISTER_SUCCESS);
    ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource).saveAuth(captor.capture());
    assertAuthHasInfo(captor.getValue(), user, hashedPassword);
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 12 with HashedPassword

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

the class RegisterAdminCommandTest method shouldRegisterOnlinePlayer.

@Test
public void shouldRegisterOnlinePlayer() {
    // given
    String user = "someone";
    String password = "Al1O3P49S5%";
    given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
    given(dataSource.isAuthAvailable(user)).willReturn(false);
    given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(true);
    HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048");
    given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
    Player player = mock(Player.class);
    given(bukkitService.getPlayerExact(user)).willReturn(player);
    String kickForAdminRegister = "Admin registered you -- log in again";
    given(commandService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
    CommandSender sender = mock(CommandSender.class);
    setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService);
    setBukkitServiceToRunTaskOptionallyAsync(bukkitService);
    // when
    command.executeCommand(sender, Arrays.asList(user, password));
    // then
    verify(validationService).validatePassword(password, user);
    verify(commandService).send(sender, MessageKey.REGISTER_SUCCESS);
    ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource).saveAuth(captor.capture());
    assertAuthHasInfo(captor.getValue(), user, hashedPassword);
    verify(player).kickPlayer(kickForAdminRegister);
}
Also used : Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 13 with HashedPassword

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

the class RegisterAdminCommandTest method shouldHandleSavingError.

@Test
public void shouldHandleSavingError() {
    // given
    String user = "test-test";
    String password = "afdjhfkt";
    given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
    given(dataSource.isAuthAvailable(user)).willReturn(false);
    given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(false);
    HashedPassword hashedPassword = new HashedPassword("235sdf4w5udsgf");
    given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
    CommandSender sender = mock(CommandSender.class);
    setBukkitServiceToRunTaskOptionallyAsync(bukkitService);
    // when
    command.executeCommand(sender, Arrays.asList(user, password));
    // then
    verify(validationService).validatePassword(password, user);
    verify(commandService).send(sender, MessageKey.ERROR);
    ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource).saveAuth(captor.capture());
    assertAuthHasInfo(captor.getValue(), user, hashedPassword);
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 14 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)

Example 15 with HashedPassword

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

the class PasswordRecoveryService method generateAndSendNewPassword.

/**
 * Generate a new password and send it to the player via
 * email. This will update the database with the new password.
 *
 * @param player The player recovering their password.
 * @param email The email to send the password to.
 */
public void generateAndSendNewPassword(Player player, String email) {
    if (!checkEmailCooldown(player)) {
        return;
    }
    String name = player.getName();
    String thePass = RandomStringUtils.generate(commonService.getProperty(RECOVERY_PASSWORD_LENGTH));
    HashedPassword hashNew = passwordSecurity.computeHash(thePass, name);
    logger.info("Generating new password for '" + name + "'");
    dataSource.updatePassword(name, hashNew);
    boolean couldSendMail = emailService.sendPasswordMail(name, email, thePass);
    if (couldSendMail) {
        commonService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
        emailCooldown.add(player.getName().toLowerCase());
    } else {
        commonService.send(player, MessageKey.EMAIL_SEND_FAILURE);
    }
}
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