Skip to content

Commit ad6c272

Browse files
committed
chore&fix: 移除passlib直接使用bcrypt修复密码校验异常的问题 报错 #ID124V
1 parent a2e1e1e commit ad6c272

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

ruoyi-fastapi-backend/requirements-pg.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ alembic==1.16.4
22
APScheduler==3.11.0
33
async-lru==2.0.5
44
asyncpg==0.30.0
5+
bcrypt==5.0.0
56
DateTime==5.5
67
fastapi[all]==0.116.1
78
loguru==0.7.3
89
openpyxl==3.1.5
910
pandas==2.3.2
10-
passlib[bcrypt]==1.7.4
1111
Pillow==11.3.0
1212
psutil==7.0.0
1313
pydantic-validation-decorator==0.1.4

ruoyi-fastapi-backend/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ alembic==1.16.4
22
APScheduler==3.11.0
33
async-lru==2.0.5
44
asyncmy==0.2.10
5+
bcrypt==5.0.0
56
DateTime==5.5
67
fastapi[all]==0.116.1
78
loguru==0.7.3
89
openpyxl==3.1.5
910
pandas==2.3.2
10-
passlib[bcrypt]==1.7.4
1111
Pillow==11.3.0
1212
psutil==7.0.0
1313
pydantic-validation-decorator==0.1.4
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from passlib.context import CryptContext
2-
3-
pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')
1+
import bcrypt
42

53

64
class PwdUtil:
@@ -9,15 +7,17 @@ class PwdUtil:
97
"""
108

119
@classmethod
12-
def verify_password(cls, plain_password, hashed_password):
10+
def verify_password(cls, plain_password: str, hashed_password: str) -> bool:
1311
"""
1412
工具方法:校验当前输入的密码与数据库存储的密码是否一致
1513
1614
:param plain_password: 当前输入的密码
1715
:param hashed_password: 数据库存储的密码
1816
:return: 校验结果
1917
"""
20-
return pwd_context.verify(plain_password, hashed_password)
18+
return (
19+
bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8')) if hashed_password else None
20+
)
2121

2222
@classmethod
2323
def get_password_hash(cls, input_password):
@@ -27,4 +27,4 @@ def get_password_hash(cls, input_password):
2727
:param input_password: 输入的密码
2828
:return: 加密成功的密码
2929
"""
30-
return pwd_context.hash(input_password)
30+
return bcrypt.hashpw(input_password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')

0 commit comments

Comments
 (0)