From 92ff8b7c4d25782d8d192def1eca804e3473c1d7 Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Sun, 6 Feb 2022 21:30:33 +0300 Subject: More migration hash algorithms --- .../limboauth/migration/MigrationHash.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/main/java/net/elytrium/limboauth/migration') diff --git a/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java b/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java index 5296534..d127b1e 100644 --- a/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java +++ b/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java @@ -22,12 +22,32 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +@SuppressWarnings("unused") public enum MigrationHash { - @SuppressWarnings("unused") AUTHME((hash, password) -> { String[] arr = hash.split("\\$"); // $SHA$salt$hash - return arr.length == 4 && arr[3].equals(MigrationHash.getSHA256(MigrationHash.getSHA256(password) + arr[2])); + return arr.length == 4 + && arr[3].equals(MigrationHash.getDigest(MigrationHash.getDigest(password, "SHA-256") + arr[2], "SHA-256")); + }), + SHA512_NP((hash, password) -> { + String[] arr = hash.split("\\$"); // SHA$salt$hash + return arr.length == 3 && arr[2].equals(MigrationHash.getDigest(password + arr[1], "SHA-512")); + }), + SHA512_P((hash, password) -> { + String[] arr = hash.split("\\$"); // $SHA$salt$hash + return arr.length == 4 && arr[3].equals(MigrationHash.getDigest(password + arr[2], "SHA-512")); + }), + SHA256_NP((hash, password) -> { + String[] arr = hash.split("\\$"); // SHA$salt$hash + return arr.length == 3 && arr[2].equals(MigrationHash.getDigest(password + arr[1], "SHA-256")); + }), + SHA256_P((hash, password) -> { + String[] arr = hash.split("\\$"); // $SHA$salt$hash + return arr.length == 4 && arr[3].equals(MigrationHash.getDigest(password + arr[2], "SHA-256")); + }), + MD5((hash, password) -> { + return hash.equals(MigrationHash.getDigest(password, "MD5")); }); final MigrationHashVerifier verifier; @@ -40,9 +60,9 @@ public enum MigrationHash { return this.verifier.checkPassword(hash, password); } - private static String getSHA256(String string) { + private static String getDigest(String string, String algo) { try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); + MessageDigest messageDigest = MessageDigest.getInstance(algo); messageDigest.reset(); messageDigest.update(string.getBytes(StandardCharsets.UTF_8)); byte[] array = messageDigest.digest(); -- cgit