Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
T
tcm-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
TCM
tcm-system
Commits
5b5d46ca
Commit
5b5d46ca
authored
Mar 12, 2025
by
dmy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
复杂密码以及验证码
parent
25226f47
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
243 additions
and
7 deletions
+243
-7
pom.xml
pom.xml
+5
-0
UserApp.java
src/main/java/com/pangding/web/UserApp.java
+2
-0
LoginController.java
...om/pangding/web/authority/controller/LoginController.java
+16
-4
CompanyMoneyDaoImpl.java
.../pangding/web/authority/dao/impl/CompanyMoneyDaoImpl.java
+1
-0
CompanyMsgDaoImpl.java
...om/pangding/web/authority/dao/impl/CompanyMsgDaoImpl.java
+0
-2
RegisterServiceImpl.java
...gding/web/authority/service/impl/RegisterServiceImpl.java
+8
-0
UserServiceImpl.java
.../pangding/web/authority/service/impl/UserServiceImpl.java
+1
-1
KaptchConfig.java
...main/java/com/pangding/web/authority/vo/KaptchConfig.java
+67
-0
CodeService.java
.../java/com/pangding/web/authority/vo/code/CodeService.java
+92
-0
CodeVo.java
src/main/java/com/pangding/web/authority/vo/code/CodeVo.java
+51
-0
No files found.
pom.xml
View file @
5b5d46ca
...
...
@@ -47,6 +47,11 @@
<groupId>
com.pangding.web
</groupId>
<artifactId>
pd-partner-ref
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.penggle
</groupId>
<artifactId>
kaptcha
</artifactId>
<version>
2.3.2
</version>
</dependency>
<dependency>
<groupId>
com.yanzuoguang
</groupId>
<artifactId>
yzg-util-redis
</artifactId>
...
...
src/main/java/com/pangding/web/UserApp.java
View file @
5b5d46ca
...
...
@@ -2,6 +2,7 @@ package com.pangding.web;
import
com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation
;
import
com.alicp.jetcache.anno.config.EnableMethodCache
;
import
com.yanzuoguang.util.helper.YzgLanguage
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -42,5 +43,6 @@ public class UserApp implements CommandLineRunner{
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
YzgLanguage
.
get
().
setDefaultLanguage
(
YzgLanguage
.
LANGUAGE_CH
);
}
}
\ No newline at end of file
src/main/java/com/pangding/web/authority/controller/LoginController.java
View file @
5b5d46ca
...
...
@@ -2,6 +2,8 @@ package com.pangding.web.authority.controller;
import
com.pangding.web.authority.service.RegisterService
;
import
com.pangding.web.authority.service.VerifyCodeService
;
import
com.pangding.web.authority.vo.code.CodeService
;
import
com.pangding.web.authority.vo.code.CodeVo
;
import
com.pangding.web.vo.system.req.LoginReqVo
;
import
com.pangding.web.vo.system.res.LoginResVo
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
...
...
@@ -10,10 +12,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.IOException
;
...
...
@@ -29,6 +28,8 @@ public class LoginController {
RegisterService
registerServiceImpl
;
@Autowired
VerifyCodeService
verifyCodeServiceImpl
;
@Autowired
CodeService
codeService
;
/**
* 登陆,验证用户名或手机号,密码是否正确
...
...
@@ -69,4 +70,15 @@ public class LoginController {
verifyCodeServiceImpl.getImage(request,response);
return new ResponseResult();
}*/
/**
* 获取验证码
*
* @return 登录结果
*/
@GetMapping
(
value
=
"/getCode"
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
@ApiOperation
(
value
=
"获取验证码"
,
notes
=
"获取验证码"
)
public
ResponseResult
<
CodeVo
>
getCode
()
{
return
ResponseResult
.
result
(
codeService
.
getCode
());
}
}
src/main/java/com/pangding/web/authority/dao/impl/CompanyMoneyDaoImpl.java
View file @
5b5d46ca
...
...
@@ -66,6 +66,7 @@ public class CompanyMoneyDaoImpl extends BaseDaoImpl implements CompanyMoneyDao
}
@Override
public
PageSizeData
<
CompanyMoneyVo
>
findCompanyMoneyPage
(
CompanyMoneyReqVo
req
)
{
return
this
.
queryPage
(
CompanyMoneyVo
.
class
,
req
,
QUERY_LIST
,
req
);
...
...
src/main/java/com/pangding/web/authority/dao/impl/CompanyMsgDaoImpl.java
View file @
5b5d46ca
...
...
@@ -16,8 +16,6 @@ public class CompanyMsgDaoImpl extends BaseDaoImpl implements CompanyMsgDao {
private
static
final
String
QUERY_LIST_PAGE
=
"QUERY_LIST_PAGE"
;
private
static
final
String
QUERY_LIST
=
"QUERY_LIST"
;
@Override
protected
void
init
()
{
...
...
src/main/java/com/pangding/web/authority/service/impl/RegisterServiceImpl.java
View file @
5b5d46ca
...
...
@@ -8,6 +8,7 @@ import com.pangding.web.authority.feign.PayFeign;
import
com.pangding.web.authority.feign.StoreFeign
;
import
com.pangding.web.authority.service.*
;
import
com.pangding.web.authority.util.*
;
import
com.pangding.web.authority.vo.code.CodeService
;
import
com.pangding.web.authority.vo.reqvo.*
;
import
com.pangding.web.authority.vo.resvo.SaveCompanyResVo
;
import
com.pangding.web.constant.CompanyConstant
;
...
...
@@ -80,6 +81,8 @@ public class RegisterServiceImpl implements RegisterService {
private
TokenService
tokenService
;
@Autowired
private
CompanyService
companyService
;
@Autowired
private
CodeService
codeService
;
/**
* 判断注册编码是否存在
...
...
@@ -393,6 +396,11 @@ public class RegisterServiceImpl implements RegisterService {
*/
@Override
public
LoginResVo
login
(
LoginReqVo
reqVo
)
throws
Exception
{
// 当输入用户名和密码时,检测验证码
List
<
String
>
items
=
new
ArrayList
<>();
items
.
add
(
reqVo
.
getAccountOrPhone
());
items
.
add
(
reqVo
.
getPassword
());
codeService
.
validate
(
reqVo
.
getCodeId
(),
reqVo
.
getCodeValue
(),
items
);
UserReqVo
userReqVo
=
new
UserReqVo
();
userReqVo
.
setLoginAccount
(
reqVo
.
getAccountOrPhone
());
...
...
src/main/java/com/pangding/web/authority/service/impl/UserServiceImpl.java
View file @
5b5d46ca
...
...
@@ -413,7 +413,7 @@ public class UserServiceImpl implements UserService {
userVo
.
setPassword
(
this
.
passwordEncoder
(
webUserReqVo
.
getPassword
()));
}
//短信验证,通过后才可以
String
verifyCode
=
verifyCodeCache
.
get
(
user
Vo
.
getPhone
());
String
verifyCode
=
verifyCodeCache
.
get
(
webUserReq
Vo
.
getPhone
());
if
(!
webUserReqVo
.
getVerifyCode
().
equals
(
verifyCode
))
{
throw
new
CodeException
(
"验证码错误"
);
}
...
...
src/main/java/com/pangding/web/authority/vo/KaptchConfig.java
0 → 100644
View file @
5b5d46ca
package
com
.
pangding
.
web
.
authority
.
vo
;
import
com.google.code.kaptcha.impl.DefaultKaptcha
;
import
com.google.code.kaptcha.util.Config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
java.util.Properties
;
/**
* 验证码生成配置
*
* @author 颜佐光
*/
@Component
public
class
KaptchConfig
{
@Bean
public
DefaultKaptcha
getDefaultKaptcha
()
{
DefaultKaptcha
defaultKaptcha
=
new
DefaultKaptcha
();
Properties
properties
=
new
Properties
();
// 图片边框
properties
.
setProperty
(
"kaptcha.border"
,
"no"
);
// 边框颜色
properties
.
setProperty
(
"kaptcha.border.color"
,
"black"
);
//边框厚度
properties
.
setProperty
(
"kaptcha.border.thickness"
,
"1"
);
// 图片宽
properties
.
setProperty
(
"kaptcha.image.width"
,
"120"
);
// 图片高
properties
.
setProperty
(
"kaptcha.image.height"
,
"60"
);
//图片实现类
properties
.
setProperty
(
"kaptcha.producer.impl"
,
"com.google.code.kaptcha.impl.DefaultKaptcha"
);
//文本实现类
properties
.
setProperty
(
"kaptcha.textproducer.impl"
,
"com.google.code.kaptcha.text.impl.DefaultTextCreator"
);
//文本集合,验证码值从此集合中获取
// properties.setProperty("kaptcha.textproducer.char.string", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
properties
.
setProperty
(
"kaptcha.textproducer.char.string"
,
"23456789ABCDEFGHJKMNPQRSTUVWXYZ"
);
//验证码长度
properties
.
setProperty
(
"kaptcha.textproducer.char.length"
,
"4"
);
//字体
properties
.
setProperty
(
"kaptcha.textproducer.font.names"
,
"宋体"
);
//字体颜色
properties
.
setProperty
(
"kaptcha.textproducer.font.color"
,
"black"
);
//文字间隔
properties
.
setProperty
(
"kaptcha.textproducer.char.space"
,
"2"
);
//干扰实现类
properties
.
setProperty
(
"kaptcha.noise.impl"
,
"com.google.code.kaptcha.impl.DefaultNoise"
);
//干扰颜色
properties
.
setProperty
(
"kaptcha.noise.color"
,
"blue"
);
//干扰图片样式
properties
.
setProperty
(
"kaptcha.obscurificator.impl"
,
"com.google.code.kaptcha.impl.WaterRipple"
);
//背景实现类
properties
.
setProperty
(
"kaptcha.background.impl"
,
"com.google.code.kaptcha.impl.DefaultBackground"
);
// 验证码背景颜色(开始颜色)
properties
.
setProperty
(
"kaptcha.background-color.from"
,
"lightGray"
);
// 验证码背景颜色(结束颜色)
properties
.
setProperty
(
"kaptcha.background-color.to"
,
"white"
);
//背景颜色渐变,结束颜色
properties
.
setProperty
(
"kaptcha.background.clear.to"
,
"white"
);
//文字渲染器
properties
.
setProperty
(
"kaptcha.word.impl"
,
"com.google.code.kaptcha.text.impl.DefaultWordRenderer"
);
Config
config
=
new
Config
(
properties
);
defaultKaptcha
.
setConfig
(
config
);
return
defaultKaptcha
;
}
}
src/main/java/com/pangding/web/authority/vo/code/CodeService.java
0 → 100644
View file @
5b5d46ca
package
com
.
pangding
.
web
.
authority
.
vo
.
code
;
import
com.alicp.jetcache.Cache
;
import
com.alicp.jetcache.anno.CacheType
;
import
com.alicp.jetcache.anno.CreateCache
;
import
com.google.code.kaptcha.impl.DefaultKaptcha
;
import
com.pangding.web.cache.CacheName
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.stereotype.Component
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
* 验证码服务
*
*/
@Component
public
class
CodeService
{
private
final
DefaultKaptcha
defaultKaptcha
;
@CreateCache
(
name
=
CacheName
.
USER_PASSWORD_CODE
,
cacheType
=
CacheType
.
REMOTE
,
expire
=
60
,
timeUnit
=
TimeUnit
.
MINUTES
)
private
Cache
<
String
,
String
>
cache
;
public
CodeService
(
DefaultKaptcha
defaultKaptcha
)
{
this
.
defaultKaptcha
=
defaultKaptcha
;
}
/**
* 生成验证码
*
* @return 验证码效果
*/
public
CodeVo
getCode
()
{
// 生成文字验证码
String
text
=
defaultKaptcha
.
createText
();
// 生成图片验证码
BufferedImage
image
=
defaultKaptcha
.
createImage
(
text
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
image
,
"jpg"
,
out
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
// 对字节组Base64编码
String
img
=
Base64
.
getEncoder
().
encodeToString
(
out
.
toByteArray
());
CodeVo
code
=
new
CodeVo
(
StringHelper
.
getNewID
(),
img
);
// if (debugConfig.isDebug()) {
// code.setCode(text);
// }
// 验证验证码文字
cache
.
put
(
code
.
getId
(),
text
);
return
code
;
}
public
void
validate
(
String
codeId
,
String
codeValue
,
boolean
validate
)
{
if
(!
validate
)
{
return
;
}
if
(
StringHelper
.
isEmpty
(
codeId
))
{
throw
new
CodeException
(
"验证码不能为空"
);
}
String
text
=
cache
.
get
(
codeId
);
if
(
StringHelper
.
isEmpty
(
text
))
{
throw
new
CodeException
(
"验证码失效"
);
}
cache
.
remove
(
codeId
);
if
(
StringHelper
.
compare
(
text
,
codeValue
,
true
))
{
return
;
}
throw
new
CodeException
(
"验证码错误"
);
}
public
void
validate
(
String
codeId
,
String
codeValue
,
List
<
String
>
names
)
{
boolean
validate
=
false
;
for
(
String
name
:
names
)
{
if
(!
StringHelper
.
isEmpty
(
name
))
{
validate
=
true
;
break
;
}
}
this
.
validate
(
codeId
,
codeValue
,
validate
);
}
}
src/main/java/com/pangding/web/authority/vo/code/CodeVo.java
0 → 100644
View file @
5b5d46ca
package
com
.
pangding
.
web
.
authority
.
vo
.
code
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* 返回实体
*
* */
public
class
CodeVo
{
@ApiModelProperty
(
notes
=
"验证码序号"
)
private
String
id
;
@ApiModelProperty
(
notes
=
"验证码图片,base64的图片"
)
private
String
img
;
@ApiModelProperty
(
notes
=
"二维码内容,仅仅在调试模式下生效"
)
private
String
code
;
public
CodeVo
()
{
}
public
CodeVo
(
String
id
,
String
img
)
{
this
.
id
=
id
;
this
.
img
=
img
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getImg
()
{
return
img
;
}
public
void
setImg
(
String
img
)
{
this
.
img
=
img
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
}
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