This commit is contained in:
sjk
2026-01-06 19:36:42 +08:00
parent 15b579d64a
commit 19942144fb
261 changed files with 24034 additions and 5477 deletions

View File

@@ -0,0 +1,47 @@
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 字段")
}