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);
}
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);
}
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);
}
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) + "'");
}
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);
}
}
Aggregations