aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/elytrium/limboauth/migration
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2022-02-06 21:30:33 +0300
committerPetr Ilin <hevav@hevav.dev>2022-02-06 21:30:33 +0300
commit92ff8b7c4d25782d8d192def1eca804e3473c1d7 (patch)
treeb8e320206c99c766d2aae90546a0222a47806174 /src/main/java/net/elytrium/limboauth/migration
parentd9e7e89acc444e8a991ff00dc2a13ea03ed6ed20 (diff)
downloadLimboAuth-92ff8b7c4d25782d8d192def1eca804e3473c1d7.tar.gz
LimboAuth-92ff8b7c4d25782d8d192def1eca804e3473c1d7.tar.bz2
LimboAuth-92ff8b7c4d25782d8d192def1eca804e3473c1d7.zip
More migration hash algorithms
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/migration')
-rw-r--r--src/main/java/net/elytrium/limboauth/migration/MigrationHash.java28
1 files changed, 24 insertions, 4 deletions
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();