use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class SetPasswordCommand method runCommand.
@Override
protected void runCommand(Player player, List<String> arguments) {
if (recoveryService.canChangePassword(player)) {
String name = player.getName();
String password = arguments.get(0);
ValidationResult result = validationService.validatePassword(password, name);
if (!result.hasError()) {
HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
dataSource.updatePassword(name, hashedPassword);
ConsoleLogger.info("Player '" + name + "' has changed their password from recovery");
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
} else {
commonService.send(player, result.getMessageKey(), result.getArgs());
}
}
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommand method executeCommand.
@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the player and password
final String playerName = arguments.get(0);
final String playerPass = arguments.get(1);
// Validate the password
ValidationResult validationResult = validationService.validatePassword(playerPass, playerName);
if (validationResult.hasError()) {
commonService.send(sender, validationResult.getMessageKey(), validationResult.getArgs());
return;
}
// Set the password
bukkitService.runTaskOptionallyAsync(() -> changePassword(playerName.toLowerCase(), playerPass, sender));
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommand method executeCommand.
@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the player name and password
final String playerName = arguments.get(0);
final String playerPass = arguments.get(1);
final String playerNameLowerCase = playerName.toLowerCase();
// Command logic
ValidationResult passwordValidation = validationService.validatePassword(playerPass, playerName);
if (passwordValidation.hasError()) {
commonService.send(sender, passwordValidation.getMessageKey(), passwordValidation.getArgs());
return;
}
bukkitService.runTaskOptionallyAsync(new Runnable() {
@Override
public void run() {
if (dataSource.isAuthAvailable(playerNameLowerCase)) {
commonService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
return;
}
HashedPassword hashedPassword = passwordSecurity.computeHash(playerPass, playerNameLowerCase);
PlayerAuth auth = PlayerAuth.builder().name(playerNameLowerCase).realName(playerName).password(hashedPassword).build();
if (!dataSource.saveAuth(auth)) {
commonService.send(sender, MessageKey.ERROR);
return;
}
dataSource.setUnlogged(playerNameLowerCase);
commonService.send(sender, MessageKey.REGISTER_SUCCESS);
ConsoleLogger.info(sender.getName() + " registered " + playerName);
final Player player = bukkitService.getPlayerExact(playerName);
if (player != null) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
@Override
public void run() {
player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER));
}
});
}
}
});
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommandTest method shouldRejectInvalidPassword.
@Test
public void shouldRejectInvalidPassword() {
// given
String user = "tester";
String password = "myPassword";
given(validationService.validatePassword(password, user)).willReturn(new ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH));
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Arrays.asList(user, password));
// then
verify(validationService).validatePassword(password, user);
verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH, new String[0]);
verify(bukkitService, never()).runTaskAsynchronously(any(Runnable.class));
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommandTest method shouldUpdatePasswordOfLoggedInUser.
@Test
public void shouldUpdatePasswordOfLoggedInUser() {
// given
CommandSender sender = mock(CommandSender.class);
String player = "my_user12";
String password = "passPass";
given(playerCache.isAuthenticated(player)).willReturn(true);
HashedPassword hashedPassword = mock(HashedPassword.class);
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
// when
command.executeCommand(sender, Arrays.asList(player, password));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, player);
verify(service).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
verify(passwordSecurity).computeHash(password, player);
verify(dataSource).updatePassword(player, hashedPassword);
}
Aggregations