From 86f9f20b522d912254f5be8b38c4bbe6dc3fc8cb Mon Sep 17 00:00:00 2001 From: Gravita Date: Wed, 28 Sep 2022 16:53:56 +0700 Subject: [PATCH] [FEATURE] BCryptPasswordVerifier --- .../auth/password/BCryptPasswordVerifier.java | 17 +++++++++++++++++ .../auth/password/PasswordVerifier.java | 1 + 2 files changed, 18 insertions(+) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/BCryptPasswordVerifier.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/BCryptPasswordVerifier.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/BCryptPasswordVerifier.java new file mode 100644 index 00000000..b7df788f --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/BCryptPasswordVerifier.java @@ -0,0 +1,17 @@ +package pro.gravit.launchserver.auth.password; + +import org.bouncycastle.crypto.generators.OpenBSDBCrypt; +import pro.gravit.utils.helper.SecurityHelper; + +public class BCryptPasswordVerifier extends PasswordVerifier { + public int cost = 10; + @Override + public boolean check(String encryptedPassword, String password) { + return OpenBSDBCrypt.checkPassword(encryptedPassword, password.toCharArray()); + } + + @Override + public String encrypt(String password) { + return OpenBSDBCrypt.generate(password.toCharArray(), SecurityHelper.randomBytes(16), cost); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/PasswordVerifier.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/PasswordVerifier.java index 30c352e9..abf70f77 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/PasswordVerifier.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/PasswordVerifier.java @@ -12,6 +12,7 @@ public static void registerProviders() { providers.register("digest", DigestPasswordVerifier.class); providers.register("doubleDigest", DoubleDigestPasswordVerifier.class); providers.register("json", JsonPasswordVerifier.class); + providers.register("bcrypt", BCryptPasswordVerifier.class); providers.register("accept", AcceptPasswordVerifier.class); providers.register("reject", RejectPasswordVerifier.class); registeredProviders = true;