mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
Add bcrypt_2y for new phpbb system
This commit is contained in:
parent
9c42be39d8
commit
fa831700a2
@ -28,6 +28,7 @@ public enum HashAlgorithm {
|
||||
WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class),
|
||||
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
||||
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
||||
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
||||
CUSTOM(Null.class);
|
||||
|
||||
Class<?> classe;
|
||||
|
@ -20,7 +20,8 @@ public class PasswordSecurity {
|
||||
private static SecureRandom rnd = new SecureRandom();
|
||||
public static HashMap<String, String> userSalt = new HashMap<String, String>();
|
||||
|
||||
public static String createSalt(int length) throws NoSuchAlgorithmException {
|
||||
public static String createSalt(int length)
|
||||
throws NoSuchAlgorithmException {
|
||||
byte[] msg = new byte[40];
|
||||
rnd.nextBytes(msg);
|
||||
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
|
||||
@ -94,6 +95,10 @@ public class PasswordSecurity {
|
||||
salt = createSalt(16);
|
||||
userSalt.put(playerName, salt);
|
||||
break;
|
||||
case BCRYPT2Y:
|
||||
salt = createSalt(22);
|
||||
userSalt.put(playerName, salt);
|
||||
break;
|
||||
case MD5:
|
||||
case SHA1:
|
||||
case WHIRLPOOL:
|
||||
|
24
src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java
Normal file
24
src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java
Normal file
@ -0,0 +1,24 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class BCRYPT2Y implements EncryptionMethod {
|
||||
|
||||
@Override
|
||||
public String getHash(String password, String salt, String name)
|
||||
throws NoSuchAlgorithmException {
|
||||
if (salt.length() == 22)
|
||||
salt = "$2y$10$" + salt;
|
||||
return (BCRYPT.hashpw(password, salt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String hash, String password,
|
||||
String playerName) throws NoSuchAlgorithmException {
|
||||
String ok = hash.substring(29);
|
||||
if (ok.length() != 29)
|
||||
return false;
|
||||
return hash.equals(getHash(password, ok, playerName));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user