v2版本正式上线测试版
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
/*
|
||||
* @Author: haodaquan
|
||||
* @Date: 2017-06-20 10:01:39
|
||||
* @Last Modified by: haodaquan
|
||||
* @Last Modified time: 2017-06-20 10:02:07
|
||||
*/
|
||||
/**********************************************
|
||||
** @Des: This file ...
|
||||
** @Author: haodaquan
|
||||
** @Date: 2017-09-08 00:24:25
|
||||
** @Last Modified by: haodaquan
|
||||
** @Last Modified time: 2017-09-17 10:12:06
|
||||
***********************************************/
|
||||
|
||||
package libs
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
var emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
|
||||
@@ -35,3 +38,32 @@ func SizeFormat(size float64) string {
|
||||
func IsEmail(b []byte) bool {
|
||||
return emailPattern.Match(b)
|
||||
}
|
||||
|
||||
func Password(len int, pwdO string) (pwd string, salt string) {
|
||||
salt = GetRandomString(4)
|
||||
defaultPwd := "george518"
|
||||
if pwdO != "" {
|
||||
defaultPwd = pwdO
|
||||
}
|
||||
pwd = Md5([]byte(defaultPwd + salt))
|
||||
return pwd, salt
|
||||
}
|
||||
|
||||
// 生成32位MD5
|
||||
// func MD5(text string) string{
|
||||
// ctx := md5.New()
|
||||
// ctx.Write([]byte(text))
|
||||
// return hex.EncodeToString(ctx.Sum(nil))
|
||||
// }
|
||||
|
||||
//生成随机字符串
|
||||
func GetRandomString(lens int) string {
|
||||
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
bytes := []byte(str)
|
||||
result := []byte{}
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := 0; i < lens; i++ {
|
||||
result = append(result, bytes[r.Intn(len(bytes))])
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user