init: 1.0.0

This commit is contained in:
Chang lue Tsen
2025-04-25 12:08:29 +09:00
commit 8addcc584b
1031 changed files with 76472 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package tool
import (
"crypto/md5"
"crypto/sha512"
"encoding/hex"
"fmt"
"strings"
"github.com/anaskhan96/go-password-encoder"
)
var options = &password.Options{SaltLen: 16, Iterations: 100, KeyLen: 32, HashFunction: sha512.New}
func EncodePassWord(str string) string {
salt, encodedPwd := password.Encode(str, options)
newPassword := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)
return newPassword
}
func VerifyPassWord(passwd, EncodePasswd string) bool {
info := strings.Split(EncodePasswd, "$")
return password.Verify(passwd, info[2], info[3], options)
}
func Md5Encode(str string, isUpper bool) string {
sum := md5.Sum([]byte(str))
res := hex.EncodeToString(sum[:])
//转大写,strings.ToUpper(res)
if isUpper {
res = strings.ToUpper(res)
}
return res
}