Minor - rename EncryptedPassword to HashedPassword
- We hash passwords; we don't encrypt them
This commit is contained in:
@@ -520,13 +520,13 @@ public class BCRYPT implements EncryptionMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
String salt = generateSalt();
|
||||
return new EncryptedPassword(hashpw(password, salt), null);
|
||||
return new HashedPassword(hashpw(password, salt), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword hash, String name) {
|
||||
public boolean comparePassword(String password, HashedPassword hash, String name) {
|
||||
return checkpw(password, hash.getHash());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class BCRYPT2Y extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encrypted, String unusedName) {
|
||||
public boolean comparePassword(String password, HashedPassword encrypted, String unusedName) {
|
||||
String hash = encrypted.getHash();
|
||||
if (hash.length() != 60) {
|
||||
return false;
|
||||
|
||||
@@ -28,11 +28,11 @@ public class CRAZYCRYPT1 extends UsernameSaltMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
|
||||
final MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.SHA512);
|
||||
md.update(text.getBytes(charset), 0, text.length());
|
||||
return new EncryptedPassword(byteArrayToHexString(md.digest()));
|
||||
return new HashedPassword(byteArrayToHexString(md.digest()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ public class CryptPBKDF2 extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String unusedName) {
|
||||
String[] line = encryptedPassword.getHash().split("\\$");
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String unusedName) {
|
||||
String[] line = hashedPassword.getHash().split("\\$");
|
||||
String salt = line[2];
|
||||
String derivedKey = line[3];
|
||||
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000, derivedKey.getBytes());
|
||||
|
||||
@@ -19,8 +19,8 @@ public class CryptPBKDF2Django extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String unusedName) {
|
||||
String[] line = encryptedPassword.getHash().split("\\$");
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String unusedName) {
|
||||
String[] line = hashedPassword.getHash().split("\\$");
|
||||
String salt = line[2];
|
||||
byte[] derivedKey = DatatypeConverter.parseBase64Binary(line[3]);
|
||||
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 15000, derivedKey);
|
||||
|
||||
@@ -12,9 +12,9 @@ public interface EncryptionMethod {
|
||||
* @param name The name of the player (sometimes required to generate a salt with)
|
||||
*
|
||||
* @return The hash result for the password.
|
||||
* @see EncryptedPassword
|
||||
* @see HashedPassword
|
||||
*/
|
||||
EncryptedPassword computeHash(String password, String name);
|
||||
HashedPassword computeHash(String password, String name);
|
||||
|
||||
/**
|
||||
* Hash the given password with the given salt for the given player.
|
||||
@@ -32,12 +32,12 @@ public interface EncryptionMethod {
|
||||
* Check whether the given hash matches the clear-text password.
|
||||
*
|
||||
* @param password The clear-text password to verify
|
||||
* @param encryptedPassword The hash to check the password against
|
||||
* @param hashedPassword The hash to check the password against
|
||||
* @param name The player name to do the check for (sometimes required for generating the salt)
|
||||
*
|
||||
* @return True if the password matches, false otherwise
|
||||
*/
|
||||
boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name);
|
||||
boolean comparePassword(String password, HashedPassword hashedPassword, String name);
|
||||
|
||||
/**
|
||||
* Generate a new salt to hash a password with.
|
||||
@@ -48,7 +48,7 @@ public interface EncryptionMethod {
|
||||
|
||||
/**
|
||||
* Return whether the encryption method requires the salt to be stored separately and
|
||||
* passed again to {@link #comparePassword(String, EncryptedPassword, String)}. Note that
|
||||
* passed again to {@link #comparePassword(String, HashedPassword, String)}. Note that
|
||||
* an encryption method returning {@code false} does not imply that it uses no salt; it
|
||||
* may be embedded into the hash or it may use the username as salt.
|
||||
*
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ package fr.xephi.authme.security.crypts;
|
||||
/**
|
||||
* The result of a hash computation. See {@link #salt} for details.
|
||||
*/
|
||||
public class EncryptedPassword {
|
||||
public class HashedPassword {
|
||||
|
||||
/** The generated hash. */
|
||||
private final String hash;
|
||||
@@ -23,7 +23,7 @@ public class EncryptedPassword {
|
||||
* @param hash The computed hash
|
||||
* @param salt The generated salt
|
||||
*/
|
||||
public EncryptedPassword(String hash, String salt) {
|
||||
public HashedPassword(String hash, String salt) {
|
||||
this.hash = hash;
|
||||
this.salt = salt;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class EncryptedPassword {
|
||||
*
|
||||
* @param hash The computed hash
|
||||
*/
|
||||
public EncryptedPassword(String hash) {
|
||||
public HashedPassword(String hash) {
|
||||
this(hash, null);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ public abstract class HexSaltedMethod implements EncryptionMethod {
|
||||
public abstract String computeHash(String password, String salt, String name);
|
||||
|
||||
@Override
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
String salt = generateSalt();
|
||||
return new EncryptedPassword(computeHash(password, salt, null));
|
||||
return new HashedPassword(computeHash(password, salt, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name);
|
||||
public abstract boolean comparePassword(String password, HashedPassword hashedPassword, String name);
|
||||
|
||||
@Override
|
||||
public String generateSalt() {
|
||||
|
||||
@@ -13,8 +13,8 @@ public class JOOMLA extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String unusedName) {
|
||||
String hash = encryptedPassword.getHash();
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String unusedName) {
|
||||
String hash = hashedPassword.getHash();
|
||||
String[] hashParts = hash.split(":");
|
||||
return hashParts.length == 2 && hash.equals(computeHash(password, hashParts[1], null));
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ public class MD5VB extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
String hash = encryptedPassword.getHash();
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
String hash = hashedPassword.getHash();
|
||||
String[] line = hash.split("\\$");
|
||||
return line.length == 4 && hash.equals(computeHash(password, line[2], name));
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ public class PHPBB extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
return phpbb_check_hash(password, encryptedPassword.getHash());
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
return phpbb_check_hash(password, hashedPassword.getHash());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,8 +14,8 @@ public class SHA256 extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String playerName) {
|
||||
String hash = encryptedPassword.getHash();
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
||||
String hash = hashedPassword.getHash();
|
||||
String[] line = hash.split("\\$");
|
||||
return line.length == 4 && hash.equals(computeHash(password, line[2], ""));
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import fr.xephi.authme.security.HashUtils;
|
||||
|
||||
public class SMF extends UsernameSaltMethod {
|
||||
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
return new EncryptedPassword(HashUtils.sha1(name.toLowerCase() + password));
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
return new HashedPassword(HashUtils.sha1(name.toLowerCase() + password));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ public abstract class SeparateSaltMethod implements EncryptionMethod {
|
||||
public abstract String generateSalt();
|
||||
|
||||
@Override
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
String salt = generateSalt();
|
||||
return new EncryptedPassword(computeHash(password, salt, name), salt);
|
||||
return new HashedPassword(computeHash(password, salt, name), salt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
return encryptedPassword.getHash().equals(computeHash(password, encryptedPassword.getSalt(), null));
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
return hashedPassword.getHash().equals(computeHash(password, hashedPassword.getSalt(), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,8 +15,8 @@ public abstract class UnsaltedMethod implements EncryptionMethod {
|
||||
public abstract String computeHash(String password);
|
||||
|
||||
@Override
|
||||
public EncryptedPassword computeHash(String password, String name) {
|
||||
return new EncryptedPassword(computeHash(password));
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
return new HashedPassword(computeHash(password));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,8 +25,8 @@ public abstract class UnsaltedMethod implements EncryptionMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
return encryptedPassword.getHash().equals(computeHash(password));
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
return hashedPassword.getHash().equals(computeHash(password));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,11 +14,11 @@ import fr.xephi.authme.security.crypts.description.Usage;
|
||||
public abstract class UsernameSaltMethod implements EncryptionMethod {
|
||||
|
||||
@Override
|
||||
public abstract EncryptedPassword computeHash(String password, String name);
|
||||
public abstract HashedPassword computeHash(String password, String name);
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
return encryptedPassword.getHash().equals(computeHash(password, name).getHash());
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
return hashedPassword.getHash().equals(computeHash(password, name).getHash());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,8 +12,8 @@ public class WBB4 extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String playerName) {
|
||||
return BCRYPT.checkpw(password, encryptedPassword.getHash(), 2);
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
||||
return BCRYPT.checkpw(password, hashedPassword.getHash(), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -117,8 +117,8 @@ public class WORDPRESS extends UnsaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String name) {
|
||||
String hash = encryptedPassword.getHash();
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) {
|
||||
String hash = hashedPassword.getHash();
|
||||
String comparedHash = crypt(password, hash);
|
||||
return comparedHash.equals(hash);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public class XAUTH extends HexSaltedMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String password, EncryptedPassword encryptedPassword, String playerName) {
|
||||
String hash = encryptedPassword.getHash();
|
||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
||||
String hash = hashedPassword.getHash();
|
||||
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
|
||||
String saltFromHash = hash.substring(saltPos, saltPos + 12);
|
||||
return hash.equals(computeHash(password, saltFromHash, null));
|
||||
|
||||
Reference in New Issue
Block a user