Ultima attività 8 months ago

用 bcrypt 進行密碼加密與驗證,支援 salt、自動安全雜湊,保護你的使用者資料不被爆破!適合登入驗證與帳號系統 🚀

timmy ha revisionato questo gist 8 months ago. Vai alla revisione

Nessuna modifica

timmy ha revisionato questo gist 9 months ago. Vai alla revisione

1 file changed, 18 insertions

bcrypt_util.py(file creato)

@@ -0,0 +1,18 @@
1 + import bcrypt
2 +
3 +
4 + def encode_password(password: str) -> str:
5 + salt = bcrypt.gensalt()
6 + hashed = bcrypt.hashpw(password.encode(), salt)
7 + return hashed.decode()
8 +
9 +
10 + def check_password(password: str, hashed: str) -> bool:
11 + return bcrypt.checkpw(password.encode(), hashed.encode())
12 +
13 +
14 + if __name__ == "__main__":
15 + password = "super secret password"
16 + hashed = encode_password(password)
17 + print(hashed)
18 + print(check_password(password, hashed))
Più nuovi Più vecchi