Merge pull request #448 from MagTemTenebrius/dev

[Fix] Хеширование
This commit is contained in:
Gravit 2021-06-14 16:48:41 +07:00 committed by GitHub
commit fbd246a338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -18,7 +18,7 @@ public boolean check(String encryptedPassword, String password) {
try { try {
MessageDigest digest = MessageDigest.getInstance(algo); MessageDigest digest = MessageDigest.getInstance(algo);
byte[] bytes = SecurityHelper.fromHex(encryptedPassword); byte[] bytes = SecurityHelper.fromHex(encryptedPassword);
return Arrays.equals(password.getBytes(StandardCharsets.UTF_8), digest.digest(bytes)); return Arrays.equals(bytes, digest.digest(password.getBytes(StandardCharsets.UTF_8)));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
logger.error("Digest algorithm {} not supported", algo); logger.error("Digest algorithm {} not supported", algo);
return false; return false;

View file

@ -18,9 +18,9 @@ public class DoubleDigestPasswordVerifier extends PasswordVerifier {
public boolean check(String encryptedPassword, String password) { public boolean check(String encryptedPassword, String password) {
try { try {
MessageDigest digest = MessageDigest.getInstance(algo); MessageDigest digest = MessageDigest.getInstance(algo);
byte[] bytes = SecurityHelper.fromHex(encryptedPassword); byte[] bytes = SecurityHelper.fromHex(password);
byte[] firstDigest = digest.digest(bytes); byte[] firstDigest = digest.digest(bytes);
return Arrays.equals(password.getBytes(StandardCharsets.UTF_8), toHexMode ? digest.digest(SecurityHelper.toHex(firstDigest).getBytes(StandardCharsets.UTF_8)) : digest.digest(firstDigest)); return Arrays.equals(encryptedPassword.getBytes(StandardCharsets.UTF_8), toHexMode ? digest.digest(SecurityHelper.toHex(firstDigest).getBytes(StandardCharsets.UTF_8)) : digest.digest(firstDigest));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
logger.error("Digest algorithm {} not supported", algo); logger.error("Digest algorithm {} not supported", algo);
return false; return false;