Files
hero920103 57d9866dab feat: PhotoWall 毕业照存储系统初始版本
后端: Go(Gin+GORM+MySQL+Redis)
- 17张业务表(yz_pw_前缀), 自动迁移
- JWT认证(3小时) + 盐+MD5密码 + 图形验证码
- 班级CRUD/加入(8人姓名验证/邀请码)/审核/30天自动清理
- 系统配置(16项)/菜单管理(动态路由)/数据统计
- 文件MD5去重/数据隔离/账号封禁/敏感词DFA检测

前端: Vue3+Vite+Element Plus+Less+ECharts+FontAwesome
- 动态路由(数据库菜单驱动)
- 蓝白配色, H5响应式
- 登录/注册/忘记密码/个人中心
- 班级创建向导/详情/加入/列表
- 管理后台: 审核/配置/菜单/统计/用户/敏感词

数据库: MySQL 10.31.100.3:3306/photowall
管理员: hero920103 / 920103
2026-09-03 05:55:23 +08:00

37 lines
800 B
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 hash
import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
)
// GenerateSalt 生成随机盐(16字节 hex = 32字符)
func GenerateSalt() string {
b := make([]byte, 16)
rand.Read(b)
return hex.EncodeToString(b)
}
// Password 用盐+MD5加密密码,返回 salt 和 hash
func Password(pwd string) (salt string, hash string) {
salt = GenerateSalt()
hash = MD5Salt(pwd, salt)
return
}
// MD5Salt 用指定盐计算 MD5:md5(salt + password)
func MD5Salt(pwd, salt string) string {
h := md5.New()
h.Write([]byte(salt + pwd))
return hex.EncodeToString(h.Sum(nil))
}
// Verify 验证密码:用存储的盐重新计算 MD5 比对
func Verify(storedHash, salt, pwd string) bool {
if salt == "" || storedHash == "" {
return false
}
return MD5Salt(pwd, salt) == storedHash
}