24 lines
444 B
Go
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)
|
|
}
|