Files
novalon-manage-system/test_bcrypt_strengths.py
T
张翔 af44c23f21 refactor(security): 重构安全配置并优化测试环境
- 移除旧的测试套件和UAT测试文件
- 更新密码编码器配置使用BCrypt strength=12
- 添加用户角色关联表和相关服务
- 优化前端日期显示格式
- 清理无用资源和配置文件
- 增强测试数据管理和清理功能
2026-03-27 13:00:22 +08:00

31 lines
1004 B
Python

#!/usr/bin/env python3
"""
测试 BCrypt 的不同 strength 参数
"""
import bcrypt
def test_different_strengths():
password = "admin123"
# 测试不同的 strength 值
strengths = [4, 6, 8, 10, 12, 14, 16]
for strength in strengths:
print(f"\n=== Testing strength={strength} ===")
hash_result = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(strength))
print(f"Hash: {hash_result.decode('utf-8')}")
print(f"Length: {len(hash_result)}")
# 检查哈希格式
hash_str = hash_result.decode('utf-8')
parts = hash_str.split('$')
if len(parts) >= 3:
print(f"Algorithm: {parts[1]}") # 应该是 2a 或 2b
print(f"Strength: {parts[2][:2]}") # 应该是 strength 值
# 验证密码
is_valid = bcrypt.checkpw(password.encode('utf-8'), hash_result)
print(f"Password matches: {is_valid}")
if __name__ == '__main__':
test_different_strengths()