You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
581 B

2 years ago
package common
import (
"crypto/md5"
"encoding/hex"
"fmt"
"strings"
)
//小写
func Md5Encode(data string) string {
h := md5.New()
h.Write([]byte(data))
tempStr := h.Sum(nil)
return hex.EncodeToString(tempStr)
}
//大写
func MD5Encode(data string) string {
return strings.ToUpper(Md5Encode(data))
}
//加密
func MakePassword(plainpwd, salt string) string {
return Md5Encode(plainpwd + salt)
}
//解密
func ValidPassword(plainpwd, salt string, password string) bool {
md := Md5Encode(plainpwd + salt)
fmt.Println(md + " " + password)
return md == password
}