Cryptographic utilities for password hashing, JWT tokens, HMAC signatures, and secret generation using bcrypt and jose.
# Source: https://github.com/jaikydota/BullFlow | License: MIT | Copyright 2026 中巨量(深圳)科技有限公司
# Provided via justclaw.it.com; keep this notice with the code.
"""推量发后端密码学/签名工具。
- JWT:tlf 自有密钥,自己签发自己校验
- 用户密码 bcrypt(hash_password / verify_password)
- HMAC:用于 webhook 签名(接收灵径 + 转发到子租户)
- app_key / webhook_secret:随机 + bcrypt 哈希存储
"""
from __future__ import annotations
import hashlib
import hmac
import secrets
from datetime import datetime, timedelta, timezone
import bcrypt
from jose import jwt
from tlf_app.core.config import settings
_BCRYPT_MAX_BYTES = 72
def _password_bytes(password: str) -> bytes:
return password.encode("utf-8")[:_BCRYPT_MAX_BYTES]
# ── 用户密码(AdminUser.password_hash)──
def hash_password(plain: str) -> str:
return bcrypt.hashpw(_password_bytes(plain), bcrypt.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key