Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
Overview
Overview
Details
Activity
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
吴迪
gs1-office-web-sit
Commits
89d3dbf2
Commit
89d3dbf2
authored
Dec 08, 2021
by
唐功亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】 用户注册-密码加密MD5
parent
c8443882
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
5 deletions
+124
-5
TimescodeRegiDao.java
...n/java/io/office/modules/manage/dao/TimescodeRegiDao.java
+1
-1
MemberServiceImpl.java
...office/modules/manage/service/impl/MemberServiceImpl.java
+9
-4
MD5Util.java
src/main/java/io/office/modules/manage/utils/MD5Util.java
+114
-0
No files found.
src/main/java/io/office/modules/manage/dao/TimescodeRegiDao.java
View file @
89d3dbf2
...
...
@@ -18,6 +18,6 @@ public interface TimescodeRegiDao extends BaseMapper<TimescodeRegiEntity> {
TimescodeRegiEntity
findByPhone
(
@Param
(
"phone"
)
String
phone
);
@Update
(
"UPDATE timescode_regi SET times_validate = #{times_validate} WHERE phone=#{phone}"
)
int
updateById
(
@Param
(
"phone"
)
String
phone
,
@Param
(
"times_validate"
)
Integer
times_validate
);
int
updateById
Times_validate
(
@Param
(
"phone"
)
String
phone
,
@Param
(
"times_validate"
)
Integer
times_validate
);
}
src/main/java/io/office/modules/manage/service/impl/MemberServiceImpl.java
View file @
89d3dbf2
...
...
@@ -4,6 +4,7 @@ import io.office.common.exception.RRException;
import
io.office.common.utils.IPUtils
;
import
io.office.modules.manage.dao.TimescodeRegiDao
;
import
io.office.modules.manage.entity.TimescodeRegiEntity
;
import
io.office.modules.manage.utils.MD5Util
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
...
...
@@ -76,8 +77,12 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
String
subjoinReq
=
request
.
getSession
().
getAttribute
(
"subjoin"
)==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"subjoin"
));
String
telReq
=
request
.
getSession
().
getAttribute
(
"tel"
)==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"tel"
));
Long
dateReq
=
request
.
getSession
().
getAttribute
(
"date"
)==
null
?
0
:
Long
.
valueOf
(
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"date"
)));
//毫秒值
//获取验证码验证次数
TimescodeRegiEntity
timescodeRegiEntity
=
timescodeRegiDao
.
selectById
(
phone
);
if
(
timescodeRegiEntity
==
null
){
throw
new
RRException
(
"该手机格未获取过验证码"
);
}
Integer
timesValidate
=
timescodeRegiEntity
.
getTimesValidate
();
//验证码输入错误次数;
//校验验证码
...
...
@@ -85,8 +90,8 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
//存入数据库 密码加密
MemberEntity
memberEntity
=
new
MemberEntity
();
memberEntity
.
setUsername
(
userName
);
//
TODO tgl
MD5加密密码
memberEntity
.
setPassword
(
"MD5加密"
);
//MD5加密密码
memberEntity
.
setPassword
(
MD5Util
.
md5Encrypt32Upper
(
passWord
)
);
memberEntity
.
setEmail
(
emiail
);
memberEntity
.
setPhone
(
phone
);
memberEntity
.
setOicq
(
""
);
...
...
@@ -115,7 +120,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
if
(!
sub
.
equals
(
reSub
)){
if
(
times_validate
<=
3
){
times_validate
+=
1
;
timescodeRegiDao
.
updateById
(
reTel
,
times_validate
);
timescodeRegiDao
.
updateById
Times_validate
(
reTel
,
times_validate
);
throw
new
RRException
(
"验证码已输入错误"
+
times_validate
+
"次(输入错误满3次时,该验证码失效)!"
);
}
}
...
...
@@ -140,7 +145,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
//用户名校验
public
boolean
checkUserName
(
String
logname
){
String
t1
=
"^[0-9A-Za-z]{2,8}$"
;
//判断密码用户名和密码是否为数字,字母(数字或字母)
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,
8
}$"
;
//(数字和字母)
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,
10
}$"
;
//(数字和字母)
if
(
logname
.
matches
(
t2
))
{
return
logname
.
matches
(
t2
);
}
else
{
...
...
src/main/java/io/office/modules/manage/utils/MD5Util.java
0 → 100644
View file @
89d3dbf2
package
io
.
office
.
modules
.
manage
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 1.MD5加密字符串(32位大写)
* 2.MD5加密字符串(32位小写)
* <p>
* MD5在线加密:https://md5jiami.51240.com/
* 3.将二进制字节数组转换为十六进制字符串
* 4.Unicode中文编码转换成字符串
*/
public
class
MD5Util
{
/**
* MD5加密字符串(32位大写)
*
* @param string 需要进行MD5加密的字符串
* @return 加密后的字符串(大写)
*/
public
static
String
md5Encrypt32Upper
(
String
string
)
{
byte
[]
hash
;
try
{
//创建一个MD5算法对象,并获得MD5字节数组,16*8=128位
hash
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
string
.
getBytes
(
"UTF-8"
));
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
"Huh, MD5 should be supported?"
,
e
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
"Huh, UTF-8 should be supported?"
,
e
);
}
//转换为十六进制字符串
StringBuilder
hex
=
new
StringBuilder
(
hash
.
length
*
2
);
for
(
byte
b
:
hash
)
{
if
((
b
&
0xFF
)
<
0x10
)
hex
.
append
(
"0"
);
hex
.
append
(
Integer
.
toHexString
(
b
&
0xFF
));
}
return
hex
.
toString
().
toUpperCase
();
}
/**
* MD5加密字符串(32位小写)
*
* @param string 需要进行MD5加密的字符串
* @return 加密后的字符串(小写)
*/
public
static
String
md5Encrypt32Lower
(
String
string
)
{
byte
[]
hash
;
try
{
//创建一个MD5算法对象,并获得MD5字节数组,16*8=128位
hash
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
string
.
getBytes
(
"UTF-8"
));
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
"Huh, MD5 should be supported?"
,
e
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
"Huh, UTF-8 should be supported?"
,
e
);
}
//转换为十六进制字符串
StringBuilder
hex
=
new
StringBuilder
(
hash
.
length
*
2
);
for
(
byte
b
:
hash
)
{
if
((
b
&
0xFF
)
<
0x10
)
hex
.
append
(
"0"
);
hex
.
append
(
Integer
.
toHexString
(
b
&
0xFF
));
}
return
hex
.
toString
().
toLowerCase
();
}
/**
* 将二进制字节数组转换为十六进制字符串
*
* @param bytes 二进制字节数组
* @return 十六进制字符串
*/
public
static
String
bytesToHex
(
byte
[]
bytes
)
{
StringBuffer
hexStr
=
new
StringBuffer
();
int
num
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
num
=
bytes
[
i
];
if
(
num
<
0
)
{
num
+=
256
;
}
if
(
num
<
16
)
{
hexStr
.
append
(
"0"
);
}
hexStr
.
append
(
Integer
.
toHexString
(
num
));
}
return
hexStr
.
toString
().
toUpperCase
();
}
/**
* Unicode中文编码转换成字符串
*/
public
static
String
unicodeToString
(
String
str
)
{
Pattern
pattern
=
Pattern
.
compile
(
"(\\\\u(\\p{XDigit}{4}))"
);
Matcher
matcher
=
pattern
.
matcher
(
str
);
char
ch
;
while
(
matcher
.
find
())
{
ch
=
(
char
)
Integer
.
parseInt
(
matcher
.
group
(
2
),
16
);
str
=
str
.
replace
(
matcher
.
group
(
1
),
ch
+
""
);
}
return
str
;
}
public
static
void
main
(
String
[]
args
)
{
String
md5Encrypt32Lower
=
MD5Util
.
md5Encrypt32Lower
(
"0123456789"
);
String
md5Encrypt32Upper1
=
MD5Util
.
md5Encrypt32Upper
(
"1234"
);
System
.
out
.
println
(
md5Encrypt32Lower
);
System
.
out
.
println
(
md5Encrypt32Upper1
);
}
}
\ No newline at end of file
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