- Rename getHash() to computeHash(): get.. suggests it's just retrieving some field but it's really doing a computation, which is quite complex depending on the hash algorithm
33 lines
1.0 KiB
Java
33 lines
1.0 KiB
Java
package fr.xephi.authme.security.crypts;
|
|
|
|
import java.math.BigInteger;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
/**
|
|
*/
|
|
public class JOOMLA implements EncryptionMethod {
|
|
|
|
private static String getMD5(String message)
|
|
throws NoSuchAlgorithmException {
|
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
md5.reset();
|
|
md5.update(message.getBytes());
|
|
byte[] digest = md5.digest();
|
|
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
|
}
|
|
|
|
@Override
|
|
public String computeHash(String password, String salt, String name)
|
|
throws NoSuchAlgorithmException {
|
|
return getMD5(password + salt) + ":" + salt;
|
|
}
|
|
|
|
@Override
|
|
public boolean comparePassword(String hash, String password,
|
|
String playerName) throws NoSuchAlgorithmException {
|
|
String salt = hash.split(":")[1];
|
|
return hash.equals(getMD5(password + salt) + ":" + salt);
|
|
}
|
|
}
|