2015-12-31 00:36:08 +01:00
|
|
|
package fr.xephi.authme.security.crypts;
|
|
|
|
|
2018-09-03 23:13:48 +02:00
|
|
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
2016-01-18 13:31:54 +01:00
|
|
|
|
2015-12-31 00:36:08 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2018-09-03 23:13:48 +02:00
|
|
|
public class XfBCrypt extends BCryptBasedHash {
|
|
|
|
|
2016-01-09 00:13:47 +01:00
|
|
|
public static final String SCHEME_CLASS = "XenForo_Authentication_Core12";
|
2015-12-31 05:05:18 +01:00
|
|
|
private static final Pattern HASH_PATTERN = Pattern.compile("\"hash\";s.*\"(.*)?\"");
|
2015-12-31 00:36:08 +01:00
|
|
|
|
2018-09-03 23:13:48 +02:00
|
|
|
XfBCrypt() {
|
|
|
|
super(new BCryptHasher(BCrypt.Version.VERSION_2A, 10));
|
2015-12-31 00:36:08 +01:00
|
|
|
}
|
|
|
|
|
2017-07-16 23:07:13 +02:00
|
|
|
/**
|
|
|
|
* Extracts the password hash from the given BLOB.
|
|
|
|
*
|
|
|
|
* @param blob the blob to process
|
|
|
|
* @return the extracted hash
|
|
|
|
*/
|
2015-12-31 05:05:18 +01:00
|
|
|
public static String getHashFromBlob(byte[] blob) {
|
|
|
|
String line = new String(blob);
|
|
|
|
Matcher m = HASH_PATTERN.matcher(line);
|
|
|
|
if (m.find()) {
|
|
|
|
return m.group(1);
|
2015-12-31 00:36:08 +01:00
|
|
|
}
|
2015-12-31 05:05:18 +01:00
|
|
|
return "*"; // what?
|
2015-12-31 00:36:08 +01:00
|
|
|
}
|
2016-01-09 00:13:47 +01:00
|
|
|
|
|
|
|
public static String serializeHash(String hash) {
|
|
|
|
return "a:1:{s:4:\"hash\";s:" + hash.length() + ":\""+hash+"\";}";
|
|
|
|
}
|
2015-12-31 00:36:08 +01:00
|
|
|
}
|