使用Crypto加密, 找回密码, 修改密码修复

This commit is contained in:
lealife
2015-09-07 15:39:46 +08:00
parent 5794f76b0a
commit c568756d16
4 changed files with 78 additions and 53 deletions

22
app/lea/Pwd.go Normal file
View File

@ -0,0 +1,22 @@
package lea
// 对比密码是否一致
// 因为之前密码是用md5加密的, 所以通过密码长度来判断
// rawPwd 原始, 用户输入的密码
func ComparePwd(rawPwd, dbPwd string) bool {
if len(dbPwd) == 32 {
return Md5(rawPwd) == dbPwd
}
hex := []byte(dbPwd)
return CompareHash(hex, rawPwd)
}
// 加密
func GenPwd(rawPwd string) string {
digest, err := GenerateHash(rawPwd)
if err != nil {
return ""
}
return string(digest)
}