Browse Source
Co-authored-by: Motov Yurii <[email protected]> Co-authored-by: Sebastián Ramírez <[email protected]>pull/11634/merge
committed by
GitHub
15 changed files with 75 additions and 77 deletions
@ -5,7 +5,7 @@ import jwt |
|||||
from fastapi import Depends, FastAPI, HTTPException, status |
from fastapi import Depends, FastAPI, HTTPException, status |
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel |
from pydantic import BaseModel |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -20,7 +20,7 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
} |
} |
||||
} |
} |
||||
@ -46,7 +46,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
||||
|
|
||||
@ -54,11 +54,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -5,7 +5,7 @@ import jwt |
|||||
from fastapi import Depends, FastAPI, HTTPException, status |
from fastapi import Depends, FastAPI, HTTPException, status |
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel |
from pydantic import BaseModel |
||||
from typing_extensions import Annotated |
from typing_extensions import Annotated |
||||
|
|
||||
@ -21,7 +21,7 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
} |
} |
||||
} |
} |
||||
@ -47,7 +47,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
||||
|
|
||||
@ -55,11 +55,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -5,7 +5,7 @@ import jwt |
|||||
from fastapi import Depends, FastAPI, HTTPException, status |
from fastapi import Depends, FastAPI, HTTPException, status |
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel |
from pydantic import BaseModel |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -20,7 +20,7 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
} |
} |
||||
} |
} |
||||
@ -46,7 +46,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
||||
|
|
||||
@ -54,11 +54,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -5,7 +5,7 @@ import jwt |
|||||
from fastapi import Depends, FastAPI, HTTPException, status |
from fastapi import Depends, FastAPI, HTTPException, status |
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel |
from pydantic import BaseModel |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -20,7 +20,7 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
} |
} |
||||
} |
} |
||||
@ -46,7 +46,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
||||
|
|
||||
@ -54,11 +54,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -4,7 +4,7 @@ import jwt |
|||||
from fastapi import Depends, FastAPI, HTTPException, status |
from fastapi import Depends, FastAPI, HTTPException, status |
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel |
from pydantic import BaseModel |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -19,7 +19,7 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
} |
} |
||||
} |
} |
||||
@ -45,7 +45,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") |
||||
|
|
||||
@ -53,11 +53,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -9,7 +9,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -24,14 +24,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -58,7 +58,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -69,11 +69,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -9,7 +9,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
from typing_extensions import Annotated |
from typing_extensions import Annotated |
||||
|
|
||||
@ -25,14 +25,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -59,7 +59,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -70,11 +70,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -9,7 +9,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -24,14 +24,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -58,7 +58,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -69,11 +69,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -9,7 +9,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -24,14 +24,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -58,7 +58,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -69,11 +69,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -8,7 +8,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -23,14 +23,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -57,7 +57,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -68,11 +68,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
@ -9,7 +9,7 @@ from fastapi.security import ( |
|||||
SecurityScopes, |
SecurityScopes, |
||||
) |
) |
||||
from jwt.exceptions import InvalidTokenError |
from jwt.exceptions import InvalidTokenError |
||||
from passlib.context import CryptContext |
from pwdlib import PasswordHash |
||||
from pydantic import BaseModel, ValidationError |
from pydantic import BaseModel, ValidationError |
||||
|
|
||||
# to get a string like this run: |
# to get a string like this run: |
||||
@ -24,14 +24,14 @@ fake_users_db = { |
|||||
"username": "johndoe", |
"username": "johndoe", |
||||
"full_name": "John Doe", |
"full_name": "John Doe", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc", |
||||
"disabled": False, |
"disabled": False, |
||||
}, |
}, |
||||
"alice": { |
"alice": { |
||||
"username": "alice", |
"username": "alice", |
||||
"full_name": "Alice Chains", |
"full_name": "Alice Chains", |
||||
"email": "[email protected]", |
"email": "[email protected]", |
||||
"hashed_password": "$2b$12$gSvqqUPvlXP2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm", |
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$g2/AV1zwopqUntPKJavBFw$BwpRGDCyUHLvHICnwijyX8ROGoiUPwNKZ7915MeYfCE", |
||||
"disabled": True, |
"disabled": True, |
||||
}, |
}, |
||||
} |
} |
||||
@ -58,7 +58,7 @@ class UserInDB(User): |
|||||
hashed_password: str |
hashed_password: str |
||||
|
|
||||
|
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
password_hash = PasswordHash.recommended() |
||||
|
|
||||
oauth2_scheme = OAuth2PasswordBearer( |
oauth2_scheme = OAuth2PasswordBearer( |
||||
tokenUrl="token", |
tokenUrl="token", |
||||
@ -69,11 +69,11 @@ app = FastAPI() |
|||||
|
|
||||
|
|
||||
def verify_password(plain_password, hashed_password): |
def verify_password(plain_password, hashed_password): |
||||
return pwd_context.verify(plain_password, hashed_password) |
return password_hash.verify(plain_password, hashed_password) |
||||
|
|
||||
|
|
||||
def get_password_hash(password): |
def get_password_hash(password): |
||||
return pwd_context.hash(password) |
return password_hash.hash(password) |
||||
|
|
||||
|
|
||||
def get_user(db, username: str): |
def get_user(db, username: str): |
||||
|
Loading…
Reference in new issue