#1627 Replace BCryptService with Maven dependency (#1629)

* #1627 Replace BCryptService with Maven dependency
- Remove BCryptService in favor of a better BCrypt implementation (Maven dependency)
- Introduce BCryptHasher wrapping the dependency with more suitable methods
- Fix inaccurate details about salt length in docu annotation: for BCrypt it's always 22 chars
- Change phpBB hash to produce 2y hashes instead of 2a

* #1627 Use UTF-8 encoding when (dis)assembling Strings

* #1627 Small test additions
This commit is contained in:
ljacqu
2018-09-03 23:13:48 +02:00
committed by GitHub
parent d39562d624
commit b22f26822b
18 changed files with 342 additions and 928 deletions
@@ -0,0 +1,48 @@
package fr.xephi.authme.security.crypts;
import fr.xephi.authme.security.crypts.description.HasSalt;
import fr.xephi.authme.security.crypts.description.Recommendation;
import fr.xephi.authme.security.crypts.description.SaltType;
import fr.xephi.authme.security.crypts.description.Usage;
import static fr.xephi.authme.security.crypts.BCryptHasher.SALT_LENGTH_ENCODED;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Abstract parent for BCrypt-based hash algorithms.
*/
@Recommendation(Usage.RECOMMENDED)
@HasSalt(value = SaltType.TEXT, length = SALT_LENGTH_ENCODED)
public abstract class BCryptBasedHash implements EncryptionMethod {
private final BCryptHasher bCryptHasher;
public BCryptBasedHash(BCryptHasher bCryptHasher) {
this.bCryptHasher = bCryptHasher;
}
@Override
public HashedPassword computeHash(String password, String name) {
return bCryptHasher.hash(password);
}
@Override
public String computeHash(String password, String salt, String name) {
return bCryptHasher.hashWithRawSalt(password, salt.getBytes(UTF_8));
}
@Override
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
return BCryptHasher.comparePassword(password, hashedPassword.getHash());
}
@Override
public String generateSalt() {
return BCryptHasher.generateSalt();
}
@Override
public boolean hasSeparateSalt() {
return false;
}
}