#743 Add proper error message for "invalid chars in password"
- Change password validation to return a ValidationResult object for passing message arguments - Remove wrapping methods in ProcessService and CommandService and use ValidationService directly
This commit is contained in:
@@ -104,18 +104,6 @@ public class CommandService {
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies whether a password is valid according to the plugin settings.
|
||||
*
|
||||
* @param password the password to verify
|
||||
* @param username the username the password is associated with
|
||||
* @return message key with the password error, or {@code null} if password is valid
|
||||
*/
|
||||
public MessageKey validatePassword(String password, String username) {
|
||||
return validationService.validatePassword(password, username);
|
||||
}
|
||||
|
||||
public boolean validateEmail(String email) {
|
||||
return validationService.validateEmail(email);
|
||||
}
|
||||
|
||||
+8
-3
@@ -10,6 +10,8 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -32,6 +34,9 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
@@ -40,9 +45,9 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
|
||||
final String playerPass = arguments.get(1);
|
||||
|
||||
// Validate the password
|
||||
MessageKey passwordError = commandService.validatePassword(playerPass, playerName);
|
||||
if (passwordError != null) {
|
||||
commandService.send(sender, passwordError);
|
||||
ValidationResult validationResult = validationService.validatePassword(playerPass, playerName);
|
||||
if (validationResult.hasError()) {
|
||||
commandService.send(sender, validationResult.getMessageKey(), validationResult.getArgs());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -29,6 +31,9 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
@@ -38,9 +43,9 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
final String playerNameLowerCase = playerName.toLowerCase();
|
||||
|
||||
// Command logic
|
||||
MessageKey passwordError = commandService.validatePassword(playerPass, playerName);
|
||||
if (passwordError != null) {
|
||||
commandService.send(sender, passwordError);
|
||||
ValidationResult passwordValidation = validationService.validatePassword(playerPass, playerName);
|
||||
if (passwordValidation.hasError()) {
|
||||
commandService.send(sender, passwordValidation.getMessageKey(), passwordValidation.getArgs());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -8,6 +8,8 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -24,6 +26,9 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
// TODO ljacqu 20160531: Remove this once change password task runs as a process (via Management)
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@@ -40,9 +45,9 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
// Make sure the password is allowed
|
||||
MessageKey passwordError = commandService.validatePassword(newPassword, name);
|
||||
if (passwordError != null) {
|
||||
commandService.send(player, passwordError);
|
||||
ValidationResult passwordValidation = validationService.validatePassword(newPassword, name);
|
||||
if (passwordValidation.hasError()) {
|
||||
commandService.send(player, passwordValidation.getMessageKey(), passwordValidation.getArgs());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user