timmy a révisé ce gist 8 months ago. Aller à la révision
Aucun changement
timmy a révisé ce gist 9 months ago. Aller à la révision
1 file changed, 18 insertions
bcrypt_util.py(fichier créé)
| @@ -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)) | |
Plus récent
Plus ancien