使用 SHA256 + salt 哈希密码 返回格式: sha256$ $
(password: str)
| 100 | |
| 101 | |
| 102 | def hash_password(password: str) -> str: |
| 103 | """ |
| 104 | 使用 SHA256 + salt 哈希密码 |
| 105 | 返回格式: sha256$<salt>$<hash> |
| 106 | """ |
| 107 | salt = os.urandom(16).hex() |
| 108 | password_hash = hashlib.sha256(f"{salt}{password}".encode()).hexdigest() |
| 109 | return f"sha256${salt}${password_hash}" |
| 110 | |
| 111 | |
| 112 | def verify_password(password: str, hashed: str) -> bool: |
no outgoing calls