aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/elytrium/limboauth/Settings.java13
-rw-r--r--src/main/java/net/elytrium/limboauth/migration/MigrationHash.java17
2 files changed, 23 insertions, 7 deletions
diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java
index add2ea2..edbe130 100644
--- a/src/main/java/net/elytrium/limboauth/Settings.java
+++ b/src/main/java/net/elytrium/limboauth/Settings.java
@@ -69,12 +69,13 @@ public class Settings extends Config {
@Comment({
"If you want to migrate your database from another plugin, which is not using BCrypt.",
"You can set an old hash algorithm to migrate from.",
- "AUTHME - AuthMe SHA256(SHA256(password) + salt) that looks like $SHA$salt$password",
- "SHA256_NP - SHA256(password) that looks like SHA$salt$password",
- "SHA256_P - SHA256(password) that looks like $SHA$salt$password",
- "SHA512_NP - SHA512(password) that looks like SHA$salt$password",
- "SHA512_P - SHA512(password) that looks like $SHA$salt$password",
- "MD5 - Basic md5 hash"
+ "AUTHME - AuthMe SHA256(SHA256(password) + salt) that looks like $SHA$salt$hash",
+ "SHA256_NP - SHA256(password) that looks like SHA$salt$hash",
+ "SHA256_P - SHA256(password) that looks like $SHA$salt$hash",
+ "SHA512_NP - SHA512(password) that looks like SHA$salt$hash",
+ "SHA512_P - SHA512(password) that looks like $SHA$salt$hash",
+ "MD5 - Basic md5 hash",
+ "Argon2 - Argon2 hash that looks like $argon2i$v=1234$m=1234,t=1234,p=1234$hash",
})
public String MIGRATION_HASH = "";
@Comment("Available dimensions: OVERWORLD, NETHER, THE_END")
diff --git a/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java b/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java
index d127b1e..4f7ae24 100644
--- a/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java
+++ b/src/main/java/net/elytrium/limboauth/migration/MigrationHash.java
@@ -17,6 +17,8 @@
package net.elytrium.limboauth.migration;
+import de.mkammerer.argon2.Argon2;
+import de.mkammerer.argon2.Argon2Factory;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@@ -24,12 +26,12 @@ import java.security.NoSuchAlgorithmException;
@SuppressWarnings("unused")
public enum MigrationHash {
-
AUTHME((hash, password) -> {
String[] arr = hash.split("\\$"); // $SHA$salt$hash
return arr.length == 4
&& arr[3].equals(MigrationHash.getDigest(MigrationHash.getDigest(password, "SHA-256") + arr[2], "SHA-256"));
}),
+ ARGON2(new Argon2Verifier()),
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"));
@@ -71,4 +73,17 @@ public enum MigrationHash {
throw new IllegalArgumentException(e);
}
}
+
+ private static class Argon2Verifier implements MigrationHashVerifier {
+ private Argon2 argon2;
+
+ @Override
+ public boolean checkPassword(String hash, String password) {
+ if (this.argon2 == null) {
+ this.argon2 = Argon2Factory.create();
+ }
+
+ return this.argon2.verify(hash, password.getBytes(StandardCharsets.UTF_8));
+ }
+ }
}