Files
ai_wht_wechat/go_backend/cmd/generate_password.go
2026-01-06 19:36:42 +08:00

48 lines
1.3 KiB
Go
Raw Permalink 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.

package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
)
// HashPassword 密码加密使用SHA256与Python版本保持一致
func HashPassword(password string) string {
hash := sha256.Sum256([]byte(password))
return hex.EncodeToString(hash[:])
}
func main() {
// 如果有命令行参数,加密该密码
if len(os.Args) > 1 {
password := os.Args[1]
hashed := HashPassword(password)
fmt.Printf("原始密码: %s\n", password)
fmt.Printf("加密后: %s\n", hashed)
return
}
// 为测试数据生成加密密码
passwords := []string{
"admin123", // 企业管理员密码
"user123", // 普通用户密码
"123456", // 默认密码
}
fmt.Println("生成加密密码SHA256")
fmt.Println("=====================================")
for i, pwd := range passwords {
hashed := HashPassword(pwd)
fmt.Printf("%d. 原始密码: %s\n", i+1, pwd)
fmt.Printf(" 加密后: %s\n\n", hashed)
}
fmt.Println("=====================================")
fmt.Println("使用说明:")
fmt.Println("方式1直接运行此程序查看常用密码的加密结果")
fmt.Println("方式2传入密码参数如: go run generate_password.go mypassword")
fmt.Println("注意:请将加密后的密码保存到数据库的 password 字段")
}