package crypto import ( "crypto/sha256" "encoding/hex" ) // HashPassword 使用 SHA-256 对密码进行加密 func HashPassword(password string) string { hash := sha256.New() hash.Write([]byte(password)) return hex.EncodeToString(hash.Sum(nil)) } // VerifyPassword 验证密码是否匹配 func VerifyPassword(password, hashedPassword string) bool { return HashPassword(password) == hashedPassword }