From fb4beedd7ee92777711a854c1c264db460a38d49 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期五, 11 四月 2025 09:56:29 +0800 Subject: [PATCH] 首页模型 --- app/utils/password_handle.py | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/utils/password_handle.py b/app/utils/password_handle.py index 8852a11..48063ed 100644 --- a/app/utils/password_handle.py +++ b/app/utils/password_handle.py @@ -2,6 +2,10 @@ import random import string +from cryptography.fernet import Fernet +from app.config.config import settings + +cipher_suite = Fernet(settings.PASSWORD_KEY.encode("utf-8")) async def generate_password(length=10): if length < 6: # 鑷冲皯闇�瑕�3浣嶅瘑鐮佷互鍖呭惈鎵�鏈夊繀瑕佺殑瀛楃 @@ -24,8 +28,22 @@ # 灏嗗垪琛ㄨ浆鎹负瀛楃涓� return ''.join(password) + +async def password_encrypted(password): + hash_pwd = cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") + # print(hash_pwd) + return hash_pwd + + +async def password_decrypted(hash_password): + pwd = cipher_suite.decrypt(hash_password).decode("utf-8") + # print(pwd) + return pwd if __name__ == "__main__": # 鐢熸垚涓�涓�10浣嶇殑瀵嗙爜 - asyncio.run(generate_password(10)) + # asyncio.run(generate_password(10)) # password = generate_password(10) - # print(password) \ No newline at end of file + # print(password) + + asyncio.run(password_encrypted("zhaoqg123456")) + asyncio.run(password_decrypted("gAAAAABnh2Y-OYrpdm2QuW24j4QL3pxjkKZsHu37Vzl_mh8SrG5Roa5TThcBxcj7hqPq7NrA8OaL0WdsmpcpYDfpZCofBVjbbA==")) \ No newline at end of file -- Gitblit v1.8.0