Skip to content

Commit

Permalink
Fixed bug in /changepassword when using FileDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
imaohw committed Sep 30, 2011
1 parent dba26da commit 4997e70
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/uk/org/whoami/authme/commands/AdminCommand.java
Expand Up @@ -92,8 +92,17 @@ public boolean onCommand(CommandSender sender, Command cmnd, String label, Strin
String name = args[1].toLowerCase();
String hash = PasswordSecurity.getHash(settings.getPasswordHash(), args[2]);

PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", new Date(0));

PlayerAuth auth = null;
if(PlayerCache.getInstance().isAuthenticated(name)) {
auth = PlayerCache.getInstance().getAuth(name);
} else if(database.isAuthAvailable(name)) {
auth = database.getAuth(name);
} else {
sender.sendMessage(m._("unknown_user"));
return true;
}
auth.setHash(hash);

if (!database.updatePassword(auth)) {
sender.sendMessage(m._("error"));
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/uk/org/whoami/authme/commands/ChangePasswordCommand.java
Expand Up @@ -69,7 +69,8 @@ public boolean onCommand(CommandSender sender, Command cmnd, String label, Strin
String hashnew = PasswordSecurity.getHash(settings.getPasswordHash(), args[1]);

if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash())) {
PlayerAuth auth = new PlayerAuth(name, hashnew, ip, new Date(0));
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
auth.setHash(hashnew);
if (!database.updatePassword(auth)) {
player.sendMessage(m._("error"));
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/uk/org/whoami/authme/datasource/FileDataSource.java
Expand Up @@ -107,7 +107,7 @@ public synchronized boolean updatePassword(PlayerAuth auth) {
while ((line = br.readLine()) != null) {
String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], new Date(Long.parseLong(args[4])));
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], new Date(Long.parseLong(args[3])));
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/uk/org/whoami/authme/settings/Messages.java
Expand Up @@ -57,6 +57,7 @@ private void loadDefaults() {
map.put("reg_voluntarily", "You can register your nickname with the server with the command \"/register password\"");
map.put("reload", "Configuration and database has been reloaded");
map.put("error", "An error ocurred; Please contact the admin");
map.put("unknown_user", "User is not in database");
}

private void loadFile() {
Expand Down

0 comments on commit 4997e70

Please sign in to comment.