ljacqu c0a393b8b3 Minor - rename EncryptedPassword to HashedPassword
- We hash passwords; we don't encrypt them
2015-12-30 22:51:59 +01:00

35 lines
953 B
Java

package fr.xephi.authme.security.crypts;
import fr.xephi.authme.security.crypts.description.Recommendation;
import fr.xephi.authme.security.crypts.description.Usage;
@Recommendation(Usage.RECOMMENDED)
public class BCRYPT2Y extends HexSaltedMethod {
@Override
public String computeHash(String password, String salt, String name) {
if (salt.length() == 22) {
salt = "$2y$10$" + salt;
}
return BCRYPT.hashpw(password, salt);
}
@Override
public boolean comparePassword(String password, HashedPassword encrypted, String unusedName) {
String hash = encrypted.getHash();
if (hash.length() != 60) {
return false;
}
// The salt is the first 29 characters of the hash
String salt = hash.substring(0, 29);
return hash.equals(computeHash(password, salt, null));
}
@Override
public int getSaltLength() {
return 22;
}
}