|
@@ -10,14 +10,15 @@ import (
|
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
|
|
|
|
|
|
- "github.com/astaxie/beego"
|
|
|
|
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/logs"
|
|
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func HashPassword(password, salt string) string {
|
|
func HashPassword(password, salt string) string {
|
|
|
h := md5.New()
|
|
h := md5.New()
|
|
|
- enableDbSalt, _ := NewConfig().Bool("System::EnableDBSalt", true) //beego.AppConfig.Bool("System::EnableDBSalt")
|
|
|
|
|
- customSalt := NewConfig().String("System::PasswordSalt") //beego.AppConfig.String("System::PasswordSalt")
|
|
|
|
|
- enableBase64, _ := NewConfig().Bool("System::PasswordEnableBase64", true)
|
|
|
|
|
|
|
+ enableDbSalt, _ := config.AppConfig.GetBool("System::EnableDBSalt", true)
|
|
|
|
|
+ customSalt := config.AppConfig.GetKey("System::PasswordSalt")
|
|
|
|
|
+ enableBase64, _ := config.AppConfig.GetBool("System::PasswordEnableBase64", true)
|
|
|
if !enableDbSalt {
|
|
if !enableDbSalt {
|
|
|
h.Write([]byte(password))
|
|
h.Write([]byte(password))
|
|
|
if len(customSalt) > 0 {
|
|
if len(customSalt) > 0 {
|
|
@@ -26,26 +27,25 @@ func HashPassword(password, salt string) string {
|
|
|
h.Reset()
|
|
h.Reset()
|
|
|
h.Write([]byte(md5Str + customSalt))
|
|
h.Write([]byte(md5Str + customSalt))
|
|
|
}
|
|
}
|
|
|
- //if beego.AppConfig.String("System::PasswordEnableBase64") == "true" {
|
|
|
|
|
if enableBase64 {
|
|
if enableBase64 {
|
|
|
base64_str := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
|
base64_str := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
|
|
- beego.Debug("启用编码:", base64_str)
|
|
|
|
|
|
|
+ logs.Debug("启用编码:", base64_str)
|
|
|
return base64_str
|
|
return base64_str
|
|
|
} else {
|
|
} else {
|
|
|
str := hex.EncodeToString(h.Sum(nil))
|
|
str := hex.EncodeToString(h.Sum(nil))
|
|
|
- beego.Debug("未启用编码:", str)
|
|
|
|
|
|
|
+ logs.Debug("未启用编码:", str)
|
|
|
return str
|
|
return str
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
h.Write([]byte(password))
|
|
h.Write([]byte(password))
|
|
|
md5Str := hex.EncodeToString(h.Sum(nil))
|
|
md5Str := hex.EncodeToString(h.Sum(nil))
|
|
|
- beego.Debug("第一次加密:", md5Str)
|
|
|
|
|
|
|
+ logs.Debug("第一次加密:", md5Str)
|
|
|
if len(salt) > 0 {
|
|
if len(salt) > 0 {
|
|
|
h.Reset()
|
|
h.Reset()
|
|
|
h.Write([]byte(md5Str + salt))
|
|
h.Write([]byte(md5Str + salt))
|
|
|
md5Str = hex.EncodeToString(h.Sum(nil))
|
|
md5Str = hex.EncodeToString(h.Sum(nil))
|
|
|
}
|
|
}
|
|
|
- beego.Debug("第二次加密:", md5Str)
|
|
|
|
|
|
|
+ logs.Debug("第二次加密:", md5Str)
|
|
|
return md5Str
|
|
return md5Str
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|