first commit
This commit is contained in:
23
pkg/helper/passwordHelper.go
Normal file
23
pkg/helper/passwordHelper.go
Normal file
@ -0,0 +1,23 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user