mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-14 10:47:30 +08:00
error pages
This commit is contained in:
23
fastapi_admin/utils.py
Normal file
23
fastapi_admin/utils.py
Normal file
@ -0,0 +1,23 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
import bcrypt
|
||||
|
||||
|
||||
def generate_random_str(
|
||||
length: int,
|
||||
is_digit: bool = True,
|
||||
):
|
||||
if is_digit:
|
||||
all_char = string.digits
|
||||
else:
|
||||
all_char = string.ascii_letters + string.digits
|
||||
return "".join(random.sample(all_char, length))
|
||||
|
||||
|
||||
def check_password(password: str, password_hash: str):
|
||||
return bcrypt.checkpw(password.encode(), password_hash.encode())
|
||||
|
||||
|
||||
def hash_password(password: str):
|
||||
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
Reference in New Issue
Block a user