feat: 完善用户基础操作
This commit is contained in:
34
utils/md5.go
Normal file
34
utils/md5.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Package utils /**
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Md5Encode 小写
|
||||
func Md5Encode(data string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
tempStr := h.Sum(nil)
|
||||
return hex.EncodeToString(tempStr)
|
||||
}
|
||||
|
||||
// MD5Encode 大写
|
||||
func MD5Encode(data string) string {
|
||||
return strings.ToUpper(Md5Encode(data))
|
||||
}
|
||||
|
||||
// MakePassword 加密
|
||||
func MakePassword(plainpwd, salt string) string {
|
||||
return Md5Encode(plainpwd + salt)
|
||||
}
|
||||
|
||||
// ValidPassword 解密
|
||||
func ValidPassword(plainpwd, salt string, password string) bool {
|
||||
md := Md5Encode(plainpwd + salt)
|
||||
fmt.Println(md + " " + password)
|
||||
return md == password
|
||||
}
|
Reference in New Issue
Block a user