AuthMe 3.4

This commit is contained in:
Xephi
2014-06-13 05:56:59 +02:00
parent ff9ec22041
commit 2638007ada
52 changed files with 504 additions and 383 deletions
@@ -750,8 +750,35 @@ public class BCRYPT implements EncryptionMethod {
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
}
/**
* Check that a text password matches a previously hashed
* one with the specified number of rounds using recursion
*
* @param text plaintext or hashed text
* @param hashed the previously-hashed password
* @param rounds number of rounds to hash the password
* @return
*/
public static boolean checkpw(String text, String hashed, int rounds) {
boolean matched = false;
if (rounds > 0) {
String hash = hashpw(text, hashed);
if (rounds > 1) {
matched = checkpw(hash, hashed, rounds - 1);
} else {
matched = hash.compareTo(hashed) == 0;
}
} else {
matched = text.compareTo(hashed) == 0;
}
return matched;
}
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return hashpw(password, salt);
}
@@ -761,4 +788,9 @@ public class BCRYPT implements EncryptionMethod {
String playerName) throws NoSuchAlgorithmException {
return checkpw(password, hash);
}
public static String getDoubleHash(String text, String salt) {
String hash = hashpw(text, salt);
return hashpw(text, hash);
}
}
@@ -0,0 +1,44 @@
package fr.xephi.authme.security.crypts;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class CRAZYCRYPT1 implements EncryptionMethod {
protected final Charset charset = Charset.forName("UTF-8");
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
try
{
final MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(text.getBytes(charset), 0, text.length());
return byteArrayToHexString(md.digest());
}
catch (final NoSuchAlgorithmException e)
{
return null;
}
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
public static String byteArrayToHexString(final byte... args)
{
final char[] chars = new char[args.length * 2];
for (int i = 0; i < args.length; i++) {
chars[i * 2] = CRYPTCHARS[(args[i] >> 4) & 0xF];
chars[i * 2 + 1] = CRYPTCHARS[(args[i]) & 0xF];
}
return new String(chars);
}
}
@@ -9,7 +9,7 @@ import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
public class CryptPBKDF2 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String result = "pbkdf2_sha256$10000$"+salt+"$";
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
@@ -7,7 +7,7 @@ import java.security.NoSuchAlgorithmException;
public class DOUBLEMD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password));
}
@@ -15,7 +15,7 @@ public class DOUBLEMD5 implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, ""));
return hash.equals(getHash(password, "", ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
@@ -16,7 +16,7 @@ public interface EncryptionMethod {
* @return Hashing password
* @throws NoSuchAlgorithmException
*/
String getHash(String password, String salt) throws NoSuchAlgorithmException;
String getHash(String password, String salt, String name) throws NoSuchAlgorithmException;
/**
* @param hash
@@ -10,7 +10,7 @@ import fr.xephi.authme.AuthMe;
public class IPB3 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
@@ -19,7 +19,7 @@ public class IPB3 implements EncryptionMethod {
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt));
return hash.equals(getHash(password, salt, playerName));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
@@ -7,7 +7,7 @@ import java.security.NoSuchAlgorithmException;
public class JOOMLA implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password + salt) + ":" + salt;
}
@@ -7,13 +7,13 @@ import java.security.NoSuchAlgorithmException;
public class MD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt) throws NoSuchAlgorithmException {
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
return getMD5(password);
}
@Override
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, ""));
return hash.equals(getHash(password, "", ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
@@ -7,7 +7,7 @@ import java.security.NoSuchAlgorithmException;
public class MD5VB implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
}
@@ -16,7 +16,7 @@ public class MD5VB implements EncryptionMethod {
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
return hash.equals(getHash(password, line[2]));
return hash.equals(getHash(password, line[2], ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
@@ -10,7 +10,7 @@ import fr.xephi.authme.AuthMe;
public class MYBB implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt)+ getMD5(password));
}
@@ -19,7 +19,7 @@ public class MYBB implements EncryptionMethod {
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt));
return hash.equals(getHash(password, salt, playerName));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
@@ -151,7 +151,7 @@ private String _hash_gensalt_private(
}
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return phpbb_hash(password, salt);
}
@@ -15,7 +15,7 @@ import fr.xephi.authme.AuthMe;
public class PHPFUSION implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String digest = null;
String algo = "HmacSHA256";
@@ -45,7 +45,7 @@ public class PHPFUSION implements EncryptionMethod {
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt));
return hash.equals(getHash(password, salt, ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@@ -5,7 +5,7 @@ import java.security.NoSuchAlgorithmException;
public class PLAINTEXT implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return password;
}
@@ -6,20 +6,26 @@ import java.security.NoSuchAlgorithmException;
public class ROYALAUTH implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
for (byte aByteData : byteData) sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1));
return sb.toString();
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
String data = "";
for (int i = 0; i < 25; i++)
data = hash(data, salt);
return data;
}
public String hash(String password, String salt) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
for (byte aByteData : byteData)
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1));
return sb.toString();
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equalsIgnoreCase(getHash(password, ""));
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException {
return hash.equalsIgnoreCase(getHash(password, "", ""));
}
}
@@ -10,7 +10,7 @@ import fr.xephi.authme.AuthMe;
public class SALTED2MD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password) + salt);
}
@@ -7,14 +7,14 @@ import java.security.NoSuchAlgorithmException;
public class SHA1 implements EncryptionMethod {
@Override
public String getHash(String password, String salt) throws NoSuchAlgorithmException {
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
return getSHA1(password);
}
@Override
public boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException {
return hash.equals(getHash(password, ""));
return hash.equals(getHash(password, "", ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@@ -7,7 +7,7 @@ import java.security.NoSuchAlgorithmException;
public class SHA256 implements EncryptionMethod {
@Override
public String getHash(String password, String salt) throws NoSuchAlgorithmException {
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
}
@@ -15,7 +15,7 @@ public class SHA256 implements EncryptionMethod {
public boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
return hash.equals(getHash(password, line[2]));
return hash.equals(getHash(password, line[2], ""));
}
private static String getSHA256(String message) throws NoSuchAlgorithmException {
@@ -7,7 +7,7 @@ import java.security.NoSuchAlgorithmException;
public class SHA512 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA512(password);
}
@@ -15,7 +15,7 @@ public class SHA512 implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, ""));
return hash.equals(getHash(password, "", ""));
}
private static String getSHA512(String message) throws NoSuchAlgorithmException {
@@ -7,15 +7,15 @@ import java.security.NoSuchAlgorithmException;
public class SMF implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(salt.toLowerCase() + password);
return getSHA1(name.toLowerCase() + password);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, playerName.toLowerCase()));
return hash.equals(getHash(password, null, playerName));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@@ -10,7 +10,7 @@ import fr.xephi.authme.AuthMe;
public class WBB3 implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
}
@@ -19,7 +19,7 @@ public class WBB3 implements EncryptionMethod {
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt));
return hash.equals(getHash(password, salt, ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@@ -0,0 +1,19 @@
package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
public class WBB4 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return BCRYPT.getDoubleHash(password, salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return BCRYPT.checkpw(password, hash, 2);
}
}
@@ -408,7 +408,7 @@ public class WHIRLPOOL implements EncryptionMethod {
}
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
byte[] digest = new byte[DIGESTBYTES];
NESSIEinit();
@@ -420,6 +420,6 @@ public class WHIRLPOOL implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, ""));
return hash.equals(getHash(password, "", ""));
}
}
@@ -99,7 +99,7 @@ public class WORDPRESS implements EncryptionMethod {
}
@Override
public String getHash(String password, String salt) throws NoSuchAlgorithmException {
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
byte random[] = new byte[6];
this.randomGen.nextBytes(random);
return crypt(password, gensaltPrivate(stringToUtf8(new String(random))));
@@ -5,7 +5,7 @@ import java.security.NoSuchAlgorithmException;
public class XAUTH implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String hash = getWhirlpool(salt + password).toLowerCase();
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
@@ -17,7 +17,7 @@ public class XAUTH implements EncryptionMethod {
String playerName) throws NoSuchAlgorithmException {
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
String salt = hash.substring(saltPos, saltPos + 12);
return hash.equals(getHash(password, salt));
return hash.equals(getHash(password, salt, ""));
}
public static String getWhirlpool(String message) {
@@ -13,7 +13,7 @@ import fr.xephi.authme.AuthMe;
public class XF implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
}