Files
SmsReceiver-go/tools/password_hash.go
OpenClaw Agent 1da899a0f4 feat: v2.0.0 完整代码优化升级
🔴 高优先级 (6项全部完成):
- 数据库事务支持 (InsertMessageWithLog)
- SQL注入修复 (参数化查询)
- 配置验证 (Validate方法)
- 会话密钥强化 (长度验证)
- 签名验证增强 (SignVerificationResult)
- 密码哈希支持 (bcrypt)

🟡 中优先级 (15项全部完成):
- 连接池配置 (MaxOpenConns, MaxIdleConns)
- 查询优化 (范围查询, 索引)
- 健康检查增强 (/health 端点)
- API版本控制 (/api/v1/*)
- 认证中间件 (RequireAuth, RequireAPIAuth)
- 定时任务优化 (robfig/cron)
- 配置文件示例 (config.example.yaml)
- 常量定义 (config/constants.go)
- 开发文档 (DEVELOPMENT.md)

🟢 低优先级 (9项全部完成):
- Docker支持 (Dockerfile, docker-compose.yml)
- Makefile构建脚本
- 优化报告 (OPTIMIZATION_REPORT.md)
- 密码哈希工具 (tools/password_hash.go)
- 14个新文件
- 30项优化100%完成

版本: v2.0.0
2026-02-08 18:59:29 +08:00

48 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// +build ignore
// 密码哈希工具 - 用于生成管理员密码的哈希值
// 使用方法: go run tools/password_hash.go <密码>
package main
import (
"fmt"
"os"
"golang.org/x/crypto/bcrypt"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("用法: go run tools/password_hash.go <密码>")
fmt.Println()
fmt.Println("示例:")
fmt.Println(" go run tools/password_hash.go mypassword")
fmt.Println()
fmt.Println("输出:")
fmt.Println(" 生成 bcrypt 哈希值,复制到配置文件的 security.password_hash 字段")
os.Exit(1)
}
password := os.Args[1]
// 生成 bcrypt 哈希cost=12平衡安全性和性能
hash, err := bcrypt.GenerateFromPassword([]byte(password), 12)
if err != nil {
fmt.Fprintf(os.Stderr, "生成哈希失败: %v\n", err)
os.Exit(1)
}
fmt.Println("密码哈希值:")
fmt.Printf(" %s\n", hash)
fmt.Println()
fmt.Println("请将此哈希值添加到 config.yaml:")
fmt.Printf(" security:\n")
fmt.Printf(" password_hash: \"%s\"\n", string(hash))
fmt.Println()
fmt.Println("注意:")
fmt.Println(" - 一旦设置了 password_hash明文的 password 字段将被忽略")
fmt.Println(" - 每次运行会生成不同的哈希值(正常现象),但验证结果相同")
fmt.Println(" - cost=12 平衡了安全性和性能,可根据需要调整")
fmt.Println()
}