3 Star 4 Fork 1

kelvins-io/common

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
password.go 658 Bytes
一键复制 编辑 原始数据 按行查看 历史
cristiane 提交于 2020-08-01 11:47 +08:00 . 初始v1
package password
import (
"bytes"
"gitee.com/kelvins-io/common/crypt"
"gitee.com/kelvins-io/common/random"
"time"
)
func GenerateSalt() string {
ranStr := time.Now().String() + random.KrandAll(32)
var cipherTxt bytes.Buffer
cipherTxt.WriteString(ranStr)
return crypt.SHA1(cipherTxt.Bytes())
}
func GeneratePassword(password string, salt string) string {
var str = "pw:" + password + ":salt:" + salt + ":github:common"
var cipherTxt bytes.Buffer
cipherTxt.WriteString(str)
return crypt.SHA1(cipherTxt.Bytes())
}
func Check(dbPassword string, dbSalt string, password string) bool {
return dbPassword == GeneratePassword(password, dbSalt)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kelvins-io/common.git
git@gitee.com:kelvins-io/common.git
kelvins-io
common
common
v1.1.7

搜索帮助