Update 2.9.2
* Add Register API * Fix Captcha message * Translate email commands * Fix 'cannot measure distance' problem * Fix some problem with connection manager * Add DOUBLEMD5 password hashing md5(md5(password)) * Add pt_PT translate * Add Korean translate
This commit is contained in:
@@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import uk.org.whoami.authme.AuthMe;
|
||||
import uk.org.whoami.authme.ConsoleLogger;
|
||||
import uk.org.whoami.authme.Utils;
|
||||
import uk.org.whoami.authme.cache.auth.PlayerAuth;
|
||||
import uk.org.whoami.authme.cache.auth.PlayerCache;
|
||||
@@ -203,5 +204,27 @@ public class API {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a player
|
||||
* @param String playerName, String password
|
||||
* @return true if the player is register correctly
|
||||
*/
|
||||
public static boolean registerPlayer(String playerName, String password) {
|
||||
try {
|
||||
String name = playerName.toLowerCase();
|
||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
if (database.isAuthAvailable(name)) {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0);
|
||||
if (!database.saveAuth(auth)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CaptchaCommand implements CommandExecutor {
|
||||
plugin.cap.remove(name);
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
player.sendMessage("Your captcha is correct");
|
||||
player.sendMessage(m._("valid_captcha"));
|
||||
player.sendMessage(m._("login_msg"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -62,25 +62,25 @@ public class EmailCommand implements CommandExecutor {
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage("usage: /email add <Email> <confirmEmail> ");
|
||||
player.sendMessage("usage: /email change <old> <new> ");
|
||||
player.sendMessage("usage: /email recovery <Email>");
|
||||
player.sendMessage(m._("usage_email_add"));
|
||||
player.sendMessage(m._("usage_email_change"));
|
||||
player.sendMessage(m._("usage_email_recovery"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("add")) {
|
||||
if (args.length != 3) {
|
||||
player.sendMessage("[AuthMe] /email add <Email> <confirmEmail>");
|
||||
player.sendMessage(m._("usage_email_add"));
|
||||
return true;
|
||||
}
|
||||
if(args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
if (auth.getEmail() == null || !auth.getEmail().contains("your@email.com")) {
|
||||
player.sendMessage("[AuthMe] /email change <old> <new>");
|
||||
player.sendMessage("usage_email_change");
|
||||
return true;
|
||||
}
|
||||
if (!args[1].contains("@")) {
|
||||
player.sendMessage("[AuthMe] Invalid Email !");
|
||||
player.sendMessage(m._("email_invalid"));
|
||||
return true;
|
||||
}
|
||||
auth.setEmail(args[1]);
|
||||
@@ -89,10 +89,10 @@ public class EmailCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
player.sendMessage("[AuthMe] Email Added !");
|
||||
player.sendMessage(m._("email_added"));
|
||||
player.sendMessage(auth.getEmail());
|
||||
} else if (PlayerCache.getInstance().isAuthenticated(name)){
|
||||
player.sendMessage("[AuthMe] Confirm your Email ! ");
|
||||
player.sendMessage(m._("email_confirm"));
|
||||
} else {
|
||||
if (!data.isAuthAvailable(name)) {
|
||||
player.sendMessage(m._("login_msg"));
|
||||
@@ -104,27 +104,27 @@ public class EmailCommand implements CommandExecutor {
|
||||
if(PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com")) {
|
||||
player.sendMessage("[AuthMe] Please use : /email add <email> <confirmEmail>");
|
||||
player.sendMessage(m._("usage_email_add"));
|
||||
return true;
|
||||
}
|
||||
if (!args[1].equals(auth.getEmail())) {
|
||||
player.sendMessage("[AuthMe] Invalid Email !");
|
||||
if (!args[1].equals(auth.getEmail())) {
|
||||
player.sendMessage(m._("old_email_invalid"));
|
||||
return true;
|
||||
}
|
||||
if (!args[2].contains("@")) {
|
||||
player.sendMessage("[AuthMe] New Email is Invalid !");
|
||||
player.sendMessage(m._("new_email_invalid"));
|
||||
return true;
|
||||
}
|
||||
auth.setEmail(args[2]);
|
||||
if (!data.updateEmail(auth)) {
|
||||
player.sendMessage("[AuthMe] /email command only available with MySQL and SQLite");
|
||||
player.sendMessage(m._("bad_database_email"));
|
||||
return true;
|
||||
}
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
player.sendMessage("[AuthMe] Email Change !");
|
||||
player.sendMessage("[AuthMe] Your Email : " + auth.getEmail());
|
||||
player.sendMessage(m._("email_changed"));
|
||||
player.sendMessage(m._("email_defined") + auth.getEmail());
|
||||
} else if (PlayerCache.getInstance().isAuthenticated(name)){
|
||||
player.sendMessage("[AuthMe] Confirm your Email ! ");
|
||||
player.sendMessage(m._("email_confirm"));
|
||||
} else {
|
||||
if (!data.isAuthAvailable(name)) {
|
||||
player.sendMessage(m._("login_msg"));
|
||||
@@ -135,7 +135,7 @@ public class EmailCommand implements CommandExecutor {
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("recovery")) {
|
||||
if (args.length != 2) {
|
||||
player.sendMessage("usage: /email recovery <Email>");
|
||||
player.sendMessage(m._("usage_email_recovery"));
|
||||
return true;
|
||||
}
|
||||
if (plugin.mail == null) {
|
||||
@@ -167,7 +167,7 @@ public class EmailCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (!args[1].equalsIgnoreCase(auth.getEmail())) {
|
||||
player.sendMessage("[AuthMe] Invalid Email");
|
||||
player.sendMessage(m._("email_invalid"));
|
||||
return true;
|
||||
}
|
||||
final String finalhashnew = hashnew;
|
||||
@@ -180,7 +180,7 @@ public class EmailCommand implements CommandExecutor {
|
||||
}
|
||||
});
|
||||
plugin.mail.main(auth, thePass);
|
||||
player.sendMessage("[AuthMe] Recovery Email Send !");
|
||||
player.sendMessage(m._("email_send"));
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
sender.sendMessage(m._("error"));
|
||||
|
||||
@@ -153,8 +153,8 @@ private synchronized Connection getConnection3() throws SQLException {
|
||||
else {
|
||||
pconn = dataSource.getPooledConnection();
|
||||
pconn.addConnectionEventListener(poolConnectionEventListener); }
|
||||
Connection conn = pconn.getConnection();
|
||||
activeConnections++;
|
||||
Connection conn = pconn.getConnection();
|
||||
assertInnerState();
|
||||
return conn; }
|
||||
|
||||
|
||||
@@ -521,8 +521,13 @@ public class AuthMePlayerListener implements Listener {
|
||||
if (Spawn.getInstance().getLocation() != null && Spawn.getInstance().getLocation().getWorld().equals(player.getWorld()))
|
||||
spawn = Spawn.getInstance().getLocation();
|
||||
|
||||
if (!event.getPlayer().getWorld().equals(spawn.getWorld())) {
|
||||
event.getPlayer().teleport(spawn);
|
||||
return;
|
||||
}
|
||||
if ((spawn.distance(player.getLocation()) > radius) ) {
|
||||
event.getPlayer().teleport(spawn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,8 @@ public class PasswordSecurity {
|
||||
return getWBB3(password, saltwbb);
|
||||
case SHA512:
|
||||
return getSHA512(password);
|
||||
case DOUBLEMD5:
|
||||
return getMD5(getMD5(password));
|
||||
default:
|
||||
throw new NoSuchAlgorithmException("Unknown hash algorithm");
|
||||
}
|
||||
@@ -254,15 +256,14 @@ public class PasswordSecurity {
|
||||
String saltmybb = AuthMe.getInstance().database.getAuth(playername).getSalt();
|
||||
return hash.equals(getSaltedMyBB(password, saltmybb));
|
||||
}
|
||||
if(Settings.getPasswordHash == HashAlgorithm.SMF) {
|
||||
if(Settings.getPasswordHash == HashAlgorithm.SMF)
|
||||
return hash.equals(getSHA1(playername.toLowerCase() + password));
|
||||
}
|
||||
if(Settings.getPasswordHash == HashAlgorithm.XFSHA1) {
|
||||
if(Settings.getPasswordHash == HashAlgorithm.XFSHA1)
|
||||
return hash.equals(getSHA1(getSHA1(password) + Settings.getPredefinedSalt));
|
||||
}
|
||||
if(Settings.getPasswordHash == HashAlgorithm.XFSHA256) {
|
||||
if(Settings.getPasswordHash == HashAlgorithm.XFSHA256)
|
||||
return hash.equals(getSHA256(getSHA256(password)+ Settings.getPredefinedSalt));
|
||||
}
|
||||
if(Settings.getPasswordHash == HashAlgorithm.DOUBLEMD5)
|
||||
return hash.equals(getMD5(getMD5(password)));
|
||||
if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.SALTED2MD5) {
|
||||
String salt2md5 = AuthMe.getInstance().database.getAuth(playername).getSalt();
|
||||
return hash.equals(getMD5(getMD5(password) + salt2md5));
|
||||
@@ -271,19 +272,15 @@ public class PasswordSecurity {
|
||||
String saltj = hash.split(":")[1];
|
||||
return hash.equals(getMD5(password + saltj) + ":" + saltj);
|
||||
}
|
||||
if(Settings.getPasswordHash == HashAlgorithm.SHA512) {
|
||||
if(Settings.getPasswordHash == HashAlgorithm.SHA512)
|
||||
return hash.equals(getSHA512(password));
|
||||
}
|
||||
// PlainText Password
|
||||
if(hash.length() < 32 ) {
|
||||
if(hash.length() < 32 )
|
||||
return hash.equals(password);
|
||||
}
|
||||
if (hash.length() == 32) {
|
||||
if (hash.length() == 32)
|
||||
return hash.equals(getMD5(password));
|
||||
}
|
||||
if (hash.length() == 40) {
|
||||
if (hash.length() == 40)
|
||||
return hash.equals(getSHA1(password));
|
||||
}
|
||||
if (hash.length() == 140) {
|
||||
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
|
||||
String salt = hash.substring(saltPos, saltPos + 12);
|
||||
@@ -339,7 +336,7 @@ public class PasswordSecurity {
|
||||
public enum HashAlgorithm {
|
||||
|
||||
MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, PLAINTEXT, MYBB, IPB3, PHPFUSION, SMF, XFSHA1,
|
||||
XFSHA256, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512
|
||||
XFSHA256, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512, DOUBLEMD5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,17 @@ public class Messages extends CustomConfiguration {
|
||||
this.set("valid_captcha", "&cYour captcha is valid !");
|
||||
this.set("kick_forvip", "&cA VIP Player join the full server!");
|
||||
this.set("kick_fullserver", "&cThe server is actually full, Sorry!");
|
||||
this.set("usage_email_add", "&fUsage: /email add <Email> <confirmEmail> ");
|
||||
this.set("usage_email_change", "&Usage: /email change <old> <new> ");
|
||||
this.set("usage_email_recovery", "&Usage: /email recovery <Email>");
|
||||
this.set("email_add", "[AuthMe] /email add <Email> <confirmEmail>");
|
||||
this.set("new_email_invalid", "[AuthMe] New email invalid!");
|
||||
this.set("old_email_invalid", "[AuthMe] Old email invalid!");
|
||||
this.set("email_invalid", "[AuthMe] Invalid Email !");
|
||||
this.set("email_added", "[AuthMe] Email Added !");
|
||||
this.set("email_confirm", "[AuthMe] Confirm your Email !");
|
||||
this.set("email_changed", "[AuthMe] Email Change !");
|
||||
this.set("email_send", "[AuthMe] Recovery Email Send !");
|
||||
}
|
||||
|
||||
private void loadFile() {
|
||||
|
||||
@@ -588,7 +588,7 @@ public void mergeConfig() {
|
||||
}
|
||||
|
||||
public enum messagesLang {
|
||||
en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it
|
||||
en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it, ko, pt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user