Files
servicebase/pkg/helper/passwordHelper.go
2025-11-18 17:48:20 +08:00

24 lines
444 B
Go

package helper
import (
"crypto/md5"
"encoding/hex"
"math/rand"
"strconv"
"time"
)
// 获取随机盐值
func PasswordSalt() string {
randInt := rand.New(rand.NewSource(time.Now().UnixNano()))
return strconv.Itoa(randInt.Int() % 10000)
}
// 计算加密后的密码
func PasswordWithMd5(password, salt string) string {
h := md5.New()
h.Write([]byte(password + salt))
cipherStr := h.Sum(nil)
return hex.EncodeToString(cipherStr)
}