Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
caosy
/
fun-common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
56622469
authored
Mar 11, 2019
by
zhangchen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'f-6.7.0' of 192.168.10.6:caosy/fun-common into f-6.7.0
parents
31944e81
4cc69d03
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
fun-common-core/src/main/java/com/ctrip/fun/common/core/util/CheckPassword.java
fun-common-core/src/main/java/com/ctrip/fun/common/core/util/CheckPassword.java
0 → 100644
View file @
56622469
package
com
.
ctrip
.
fun
.
common
.
core
.
util
;
public
class
CheckPassword
{
/**
* 密码强度
*
* @return Z = 字母 S = 数字 T = 特殊字符
*/
/* 一、假定密码字符数范围6-16,除英文数字和字母外的字符都视为特殊字符:
弱:^[0-9A-Za-z]{6,16}$
中:^(?=.{6,16})[0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*$
强:^(?=.{6,16})([0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*){2,}$
二、假定密码字符数范围6-16,密码字符允许范围为ASCII码表字符:
弱:^[0-9A-Za-z]{6,16}$
中:^(?=.{6,16})[0-9A-Za-z]*[\x00-\x2f\x3A-\x40\x5B-\xFF][0-9A-Za-z]*$
强:^(?=.{6,16})([0-9A-Za-z]*[\x00-\x2F\x3A-\x40\x5B-\xFF][0-9A-Za-z]*){2,}$*/
public
static
int
checkPassword
(
String
passwordStr
)
{
if
(
passwordStr
.
length
()<
6
){
return
-
1
;
}
String
regexZ
=
"\\d*"
;
String
regexS
=
"[a-zA-Z]+"
;
String
regexT
=
"\\W+$"
;
String
regexZT
=
"\\D*"
;
String
regexST
=
"[\\d\\W]*"
;
String
regexZS
=
"\\w*"
;
String
regexZST
=
"[\\w\\W]*"
;
if
(
passwordStr
.
matches
(
regexZ
))
{
return
1
;
}
if
(
passwordStr
.
matches
(
regexS
))
{
return
1
;
}
if
(
passwordStr
.
matches
(
regexT
))
{
return
1
;
}
if
(
passwordStr
.
matches
(
regexZT
))
{
return
2
;
}
if
(
passwordStr
.
matches
(
regexST
))
{
return
2
;
}
if
(
passwordStr
.
matches
(
regexZS
))
{
return
2
;
}
if
(
passwordStr
.
matches
(
regexZST
))
{
return
3
;
}
return
1
;
}
public
static
void
main
(
String
args
[]){
String
pswd
=
"Huan3"
;
Integer
strength
=
CheckPassword
.
checkPassword
(
pswd
);
System
.
out
.
println
(
"密码强度: "
+
strength
);
}
}
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