1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Merge pull request #2362 from GNS3/feature/use-bcrypt

Use bcrypt direcrtly instead of passlib
This commit is contained in:
Jeremy Grossmann 2024-03-08 01:33:41 +08:00 committed by GitHub
commit 03b491f7b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -17,7 +17,7 @@
from jose import JWTError, jwt
from datetime import datetime, timedelta
from passlib.context import CryptContext
import bcrypt
from typing import Optional
from fastapi import HTTPException, status
@ -29,8 +29,6 @@ import logging
log = logging.getLogger(__name__)
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
DEFAULT_JWT_SECRET_KEY = "efd08eccec3bd0a1be2e086670e5efa90969c68d07e072d7354a76cea5e33d4e"
@ -38,11 +36,13 @@ class AuthService:
def hash_password(self, password: str) -> str:
return pwd_context.hash(password)
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password=password.encode('utf-8'), salt=salt)
return hashed_password.decode('utf-8')
def verify_password(self, password, hashed_password) -> bool:
return pwd_context.verify(password, hashed_password)
return bcrypt.checkpw(password=password.encode('utf-8'), hashed_password=hashed_password.encode('utf-8'))
def create_access_token(self, username, secret_key: str = None, expires_in: int = 0) -> str:

View File

@ -13,7 +13,7 @@ py-cpuinfo==9.0.0
sqlalchemy==2.0.28
aiosqlite==0.20.0
alembic==1.12.1
passlib[bcrypt]==1.7.4
bcrypt==4.1.2
python-jose==3.3.0
email-validator==2.1.1
watchfiles==0.21.0