mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[Fix] Хеширование
This commit is contained in:
parent
25ddb485ac
commit
781ab27127
1 changed files with 7 additions and 2 deletions
|
@ -4,6 +4,8 @@
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -17,8 +19,11 @@ public class DigestPasswordVerifier 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);
|
digest.update(password.getBytes(StandardCharsets.UTF_8));
|
||||||
return Arrays.equals(password.getBytes(StandardCharsets.UTF_8), digest.digest(bytes));
|
byte[] bytes = digest.digest();
|
||||||
|
String myHash = DatatypeConverter
|
||||||
|
.printHexBinary(bytes);
|
||||||
|
return myHash.equalsIgnoreCase(encryptedPassword);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
logger.error("Digest algorithm {} not supported", algo);
|
logger.error("Digest algorithm {} not supported", algo);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue