Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
5de7af9d
Commit
5de7af9d
authored
Jul 26, 2022
by
李健华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改校验密码都优先判断新加密方式
parent
a5fbd6fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
21 deletions
+46
-21
UserController.java
...n/quantgroup/xyqb/controller/external/UserController.java
+31
-18
PwdVerifyStrategy.java
...yqb/controller/middleoffice/common/PwdVerifyStrategy.java
+10
-0
UserRegisterServiceImpl.java
...p/xyqb/service/register/impl/UserRegisterServiceImpl.java
+2
-1
UserServiceImpl.java
...cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
+3
-2
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/UserController.java
View file @
5de7af9d
...
@@ -332,7 +332,8 @@ public class UserController implements IBaseController {
...
@@ -332,7 +332,8 @@ public class UserController implements IBaseController {
verifyPhoneAndCode
(
phoneNo
,
verificationCode
);
verifyPhoneAndCode
(
phoneNo
,
verificationCode
);
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
user
.
setPassword
(
PasswordUtil
.
MD5WithSalt
(
password
));
// 用户注册使用新加密方式
// user.setPassword(PasswordUtil.MD5WithSalt(password));
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
userService
.
saveUser
(
user
);
userService
.
saveUser
(
user
);
log
.
info
(
"用户注册失败,该手机号已经被注册:register -> registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
log
.
info
(
"用户注册失败,该手机号已经被注册:register -> registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
...
@@ -454,9 +455,17 @@ public class UserController implements IBaseController {
...
@@ -454,9 +455,17 @@ public class UserController implements IBaseController {
if
(
StringUtils
.
isBlank
(
user
.
getPassword
())
^
StringUtils
.
isBlank
(
password
))
{
if
(
StringUtils
.
isBlank
(
user
.
getPassword
())
^
StringUtils
.
isBlank
(
password
))
{
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
}
if
(
StringUtils
.
isNotBlank
(
user
.
getPassword
())
&&
!
PasswordUtil
.
validatePassword
(
password
,
user
.
getPassword
()))
{
// 优先校验新的密码
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
if
(
StringUtils
.
isNotBlank
(
user
.
getEncryptedPassword
())
)
{
if
(!
BctyptPasswordUtil
.
BCryptCheckPw
(
password
,
user
.
getEncryptedPassword
()))
{
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
}
else
{
if
(
StringUtils
.
isNotBlank
(
user
.
getPassword
())
&&
!
PasswordUtil
.
validatePassword
(
password
,
user
.
getPassword
()))
{
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
}
}
if
(!
userService
.
resetPassword
(
phoneNo
,
passwordNew
))
{
if
(!
userService
.
resetPassword
(
phoneNo
,
passwordNew
))
{
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
}
...
@@ -740,21 +749,25 @@ public class UserController implements IBaseController {
...
@@ -740,21 +749,25 @@ public class UserController implements IBaseController {
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
return
null
;
return
null
;
}
}
System
.
out
.
println
(
user
.
getPassword
());
if
(!
BctyptPasswordUtil
.
BCryptCheckPw
(
pass
,
user
.
getEncryptedPassword
()))
{
// 优先校验新密码加密方式 如果有并且密码校验不通过
// 向该ipv4添加错误计数器
if
(
StringUtils
.
isNotBlank
(
user
.
getEncryptedPassword
()))
{
lockIpv4Service
.
countErrorByIpv4
(
clientIp
);
if
(!
BctyptPasswordUtil
.
BCryptCheckPw
(
pass
,
user
.
getEncryptedPassword
()))
{
// 向该phoneNo添加错误计数器
// 向该ipv4添加错误计数器
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
lockIpv4Service
.
countErrorByIpv4
(
clientIp
);
return
null
;
// 向该phoneNo添加错误计数器
}
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
//验证密码
return
null
;
if
(!
PasswordUtil
.
validatePassword
(
pass
,
user
.
getPassword
()))
{
}
// 向该ipv4添加错误计数器
}
else
{
lockIpv4Service
.
countErrorByIpv4
(
clientIp
);
//验证密码
// 向该phoneNo添加错误计数器
if
(!
PasswordUtil
.
validatePassword
(
pass
,
user
.
getPassword
()))
{
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
// 向该ipv4添加错误计数器
return
null
;
lockIpv4Service
.
countErrorByIpv4
(
clientIp
);
// 向该phoneNo添加错误计数器
lockIpv4Service
.
countErrorByPhoneNo
(
phoneNo
);
return
null
;
}
}
}
// 向该ipv4添加成功计数器
// 向该ipv4添加成功计数器
...
...
src/main/java/cn/quantgroup/xyqb/controller/middleoffice/common/PwdVerifyStrategy.java
View file @
5de7af9d
...
@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.middleoffice.common;
...
@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.middleoffice.common;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.exception.DataException
;
import
cn.quantgroup.xyqb.exception.DataException
;
import
cn.quantgroup.xyqb.util.BctyptPasswordUtil
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -19,6 +20,15 @@ public class PwdVerifyStrategy implements IVerifyStrategy {
...
@@ -19,6 +20,15 @@ public class PwdVerifyStrategy implements IVerifyStrategy {
@Override
@Override
public
void
verify
(
User
user
,
String
verify
)
{
public
void
verify
(
User
user
,
String
verify
)
{
// 如果新加密的密码不为空校验新密码
String
encryptedPassword
=
user
.
getEncryptedPassword
();
if
(!
""
.
equals
(
encryptedPassword
))
{
if
(
Objects
.
equals
(
encryptedPassword
,
BctyptPasswordUtil
.
BCryptWithSalt
(
verify
)))
{
return
;
}
throw
new
DataException
(
"用户名或密码错误"
);
}
// 否则校验旧的密码
String
password
=
user
.
getPassword
();
String
password
=
user
.
getPassword
();
if
(
Objects
.
equals
(
password
,
PasswordUtil
.
MD5WithSalt
(
verify
)))
{
if
(
Objects
.
equals
(
password
,
PasswordUtil
.
MD5WithSalt
(
verify
)))
{
return
;
return
;
...
...
src/main/java/cn/quantgroup/xyqb/service/register/impl/UserRegisterServiceImpl.java
View file @
5de7af9d
...
@@ -159,7 +159,8 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
...
@@ -159,7 +159,8 @@ public class UserRegisterServiceImpl implements IUserRegisterService {
password
=
PasswordUtil
.
generateRandomPwd
(
Constants
.
RANDOM_PWD_LEN
);
password
=
PasswordUtil
.
generateRandomPwd
(
Constants
.
RANDOM_PWD_LEN
);
}
}
if
(
StringUtils
.
isNotBlank
(
password
))
{
if
(
StringUtils
.
isNotBlank
(
password
))
{
user
.
setPassword
(
PasswordUtil
.
MD5WithSalt
(
password
));
// user.setPassword(PasswordUtil.MD5WithSalt(password));
// 新建用户使用新加密方式
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
}
}
user
=
userService
.
saveUser
(
user
);
user
=
userService
.
saveUser
(
user
);
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
View file @
5de7af9d
...
@@ -228,11 +228,12 @@ public class UserServiceImpl implements IUserService, IBaseController {
...
@@ -228,11 +228,12 @@ public class UserServiceImpl implements IUserService, IBaseController {
if
(
user
==
null
)
{
if
(
user
==
null
)
{
throw
new
RuntimeException
(
"用户["
+
phoneNo
+
"]不存在"
);
throw
new
RuntimeException
(
"用户["
+
phoneNo
+
"]不存在"
);
}
}
user
.
setPassword
(
PasswordUtil
.
MD5WithSalt
(
password
));
//修改密码使用新加密方式
// user.setPassword(PasswordUtil.MD5WithSalt(password));
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
user
.
setEncryptedPassword
(
BctyptPasswordUtil
.
BCryptWithSalt
(
password
));
user
=
userRepository
.
save
(
user
);
user
=
userRepository
.
save
(
user
);
stringRedisTemplate
.
expire
(
"usercache:xyqbuser"
+
phoneNo
,
1L
,
TimeUnit
.
MILLISECONDS
);
stringRedisTemplate
.
expire
(
"usercache:xyqbuser"
+
phoneNo
,
1L
,
TimeUnit
.
MILLISECONDS
);
return
PasswordUtil
.
validatePassword
(
password
,
user
.
get
Password
());
return
BctyptPasswordUtil
.
BCryptCheckPw
(
password
,
user
.
getEncrypted
Password
());
}
}
@Override
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment