#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:
ljacqu
2016-06-03 12:51:49 +02:00
parent 6549ebbf5e
commit 55f7e8097a
15 changed files with 163 additions and 111 deletions
@@ -104,17 +104,6 @@ public class ProcessService {
pluginManager.callEvent(event);
}
/**
* 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);
}
@@ -20,6 +20,8 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -51,6 +53,9 @@ public class AsyncRegister implements AsynchronousProcess {
@Inject
private PermissionsManager permissionsManager;
@Inject
private ValidationService validationService;
AsyncRegister() { }
private boolean preRegisterCheck(Player player, String password) {
@@ -65,9 +70,9 @@ public class AsyncRegister implements AsynchronousProcess {
//check the password safety only if it's not a automatically generated password
if (service.getProperty(SecuritySettings.PASSWORD_HASH) != HashAlgorithm.TWO_FACTOR) {
MessageKey passwordError = service.validatePassword(password, player.getName());
if (passwordError != null) {
service.send(player, passwordError);
ValidationResult passwordValidation = validationService.validatePassword(password, player.getName());
if (passwordValidation.hasError()) {
service.send(player, passwordValidation.getMessageKey(), passwordValidation.getArgs());
return false;
}
}