From 1acf9a48021d0af1d81fdf3ed8fcf8dffd020f6b Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期二, 15 四月 2025 14:20:51 +0800
Subject: [PATCH] 登录,注册,获取用户信息---接口

---
 src/main/java/com/weiwojc/utils/PasswordUtils.java |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/weiwojc/utils/PasswordUtils.java b/src/main/java/com/weiwojc/utils/PasswordUtils.java
new file mode 100644
index 0000000..9bc1300
--- /dev/null
+++ b/src/main/java/com/weiwojc/utils/PasswordUtils.java
@@ -0,0 +1,36 @@
+package com.weiwojc.utils;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.springframework.security.crypto.bcrypt.BCrypt;
+
+public class PasswordUtils {
+    
+    /**
+     * 鐢熸垚闅忔満鐩愬��
+     */
+    public static String generateSalt() {
+        return BCrypt.gensalt();
+    }
+
+    /**
+     * 浣跨敤鐩愬�煎姞瀵嗗瘑鐮�
+     */
+    public static String hashPassword(String password, String salt) {
+        return BCrypt.hashpw(password, salt);
+    }
+
+    /**
+     * 楠岃瘉瀵嗙爜
+     */
+    public static boolean verifyPassword(String password, String hashedPassword) {
+        return BCrypt.checkpw(password, hashedPassword);
+    }
+
+    /**
+     * 浠嶣Crypt鍝堝笇鍊间腑鎻愬彇鐩愬��
+     */
+    public static String extractSaltFromHash(String hashedPassword) {
+        // BCrypt鍝堝笇鐨勫墠29涓瓧绗﹀氨鏄洂鍊�
+        return hashedPassword.substring(0, 29);
+    }
+} 
\ No newline at end of file

--
Gitblit v1.9.3