mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
Add SALTEDSHA512 Encryption
This commit is contained in:
parent
3ce87f1710
commit
eec7a7f575
@ -29,6 +29,7 @@ public enum HashAlgorithm {
|
||||
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
||||
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
||||
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
||||
SALTEDSHA512(fr.xephi.authme.security.crypts.SALTEDSHA512.class),
|
||||
CUSTOM(Null.class);
|
||||
|
||||
Class<?> classe;
|
||||
|
@ -96,7 +96,12 @@ public class PasswordSecurity {
|
||||
userSalt.put(playerName, salt);
|
||||
break;
|
||||
case BCRYPT2Y:
|
||||
salt = createSalt(22);
|
||||
salt = createSalt(16);
|
||||
userSalt.put(playerName, salt);
|
||||
break;
|
||||
case SALTEDSHA512:
|
||||
salt = createSalt(32);
|
||||
userSalt.put(playerName, salt);
|
||||
break;
|
||||
case MD5:
|
||||
case SHA1:
|
||||
@ -165,7 +170,7 @@ public class PasswordSecurity {
|
||||
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
||||
if (nAuth != null) {
|
||||
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
||||
nAuth.setSalt(userSalt.get(playerName));
|
||||
nAuth.setSalt(userSalt.containsKey(playerName) ? userSalt.get(playerName) : "");
|
||||
AuthMe.getInstance().database.updatePassword(nAuth);
|
||||
AuthMe.getInstance().database.updateSalt(nAuth);
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
|
||||
public class SALTEDSHA512 implements EncryptionMethod {
|
||||
|
||||
@Override
|
||||
public String getHash(String password, String salt, String name)
|
||||
throws NoSuchAlgorithmException {
|
||||
return getSHA512(password + salt);
|
||||
}
|
||||
|
||||
@Override
|
||||
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, ""));
|
||||
}
|
||||
|
||||
private static String getSHA512(String message)
|
||||
throws NoSuchAlgorithmException {
|
||||
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
|
||||
sha512.reset();
|
||||
sha512.update(message.getBytes());
|
||||
byte[] digest = sha512.digest();
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user