fix changepassword issue. #190 #218

This commit is contained in:
DNx5 2015-09-24 18:30:24 +07:00
parent 8f446fa6af
commit 8b71f964da
2 changed files with 13 additions and 9 deletions

View File

@ -62,7 +62,7 @@ public class ChangePasswordCommand implements CommandExecutor {
return true; return true;
} }
} }
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, args[0])); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, args[0], args[1]));
return true; return true;
} }
} }

View File

@ -15,12 +15,14 @@ public class ChangePasswordTask implements Runnable {
private final AuthMe plugin; private final AuthMe plugin;
private final Player player; private final Player player;
private String password; private final String oldPassword;
private final String newPassword;
public ChangePasswordTask(AuthMe plugin, Player player, String password) { public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword) {
this.plugin = plugin; this.plugin = plugin;
this.player = player; this.player = player;
this.password = password; this.oldPassword = oldPassword;
this.newPassword = newPassword;
} }
@Override @Override
@ -28,13 +30,15 @@ public class ChangePasswordTask implements Runnable {
Messages m = Messages.getInstance(); Messages m = Messages.getInstance();
try { try {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, newPassword, name);
if (PasswordSecurity.comparePasswordWithHash(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
PlayerAuth auth = PlayerCache.getInstance().getAuth(name); if (PasswordSecurity.comparePasswordWithHash(oldPassword, auth.getHash(), player.getName())) {
auth.setHash(hashnew); auth.setHash(hashnew);
if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) {
auth.setSalt(PasswordSecurity.userSalt.get(name)); auth.setSalt(PasswordSecurity.userSalt.get(name));
else auth.setSalt(""); } else {
auth.setSalt("");
}
if (!plugin.database.updatePassword(auth)) { if (!plugin.database.updatePassword(auth)) {
m.send(player, "error"); m.send(player, "error");
return; return;