aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2022-02-06 22:24:42 +0300
committerPetr Ilin <hevav@hevav.dev>2022-02-06 22:24:42 +0300
commit5221e9a993e5aec3fe3859bf0b3d00778fbc794c (patch)
treed1a4092de2c3fae67ee34d09a8394bec73e502b0 /src/main/java
parent92ff8b7c4d25782d8d192def1eca804e3473c1d7 (diff)
downloadLimboAuth-5221e9a993e5aec3fe3859bf0b3d00778fbc794c.tar.gz
LimboAuth-5221e9a993e5aec3fe3859bf0b3d00778fbc794c.tar.bz2
LimboAuth-5221e9a993e5aec3fe3859bf0b3d00778fbc794c.zip
One more hashing algo (Argon2)
Diffstat (limited to 'src/main/java')
-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));
+ }
+ }
}