Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
57d76638
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
57d76638
编写于
8月 15, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: password strength
上级
6935c641
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
70 addition
and
19 deletion
+70
-19
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
+4
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/validator.js
+53
-16
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.test.js
...niCloud/cloudfunctions/uni-id-co/common/validator.test.js
+2
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+3
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
...uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
+4
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
+4
-0
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
浏览文件 @
57d76638
...
...
@@ -11,6 +11,10 @@ const ERROR = {
PASSWORD_ERROR_EXCEED_LIMIT
:
'
uni-id-password-error-exceed-limit
'
,
INVALID_USERNAME
:
'
uni-id-invalid-username
'
,
INVALID_PASSWORD
:
'
uni-id-invalid-password
'
,
INVALID_PASSWORD_SUPER
:
'
uni-id-invalid-password-super
'
,
INVALID_PASSWORD_STRONG
:
'
uni-id-invalid-password-strong
'
,
INVALID_PASSWORD_MEDIUM
:
'
uni-id-invalid-password-medium
'
,
INVALID_PASSWORD_WEAK
:
'
uni-id-invalid-password-weak
'
,
INVALID_MOBILE
:
'
uni-id-invalid-mobile
'
,
INVALID_EMAIL
:
'
uni-id-invalid-email
'
,
INVALID_NICKNAME
:
'
uni-id-invalid-nickname
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
浏览文件 @
57d76638
...
...
@@ -29,21 +29,6 @@ baseValidator.username = function (username) {
}
}
baseValidator
.
password
=
function
(
password
)
{
const
errCode
=
ERROR
.
INVALID_PASSWORD
if
(
!
isValidString
(
password
))
{
return
{
errCode
}
}
if
(
password
.
length
<
6
)
{
// 密码长度不能小于6
return
{
errCode
}
}
}
baseValidator
.
mobile
=
function
(
mobile
)
{
const
errCode
=
ERROR
.
INVALID_MOBILE
if
(
!
isValidString
(
mobile
))
{
...
...
@@ -245,10 +230,62 @@ function isMatchArrayType (arr, rule) {
return
true
}
// 特殊符号 https://www.ibm.com/support/pages/password-strength-rules ~!@#$%^&*_-+=`|\(){}[]:;"'<>,.?/
// const specialChar = '~!@#$%^&*_-+=`|\(){}[]:;"\'<>,.?/'
// const specialCharRegExp = /^[~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]$/
// for (let i = 0, arr = specialChar.split(''); i < arr.length; i++) {
// const char = arr[i]
// if (!specialCharRegExp.test(char)) {
// throw new Error('check special character error: ' + char)
// }
// }
// 密码强度表达式
const
passwordRules
=
{
// 密码必须包含大小写字母、数字和特殊符号
super
:
/^
(?=
.*
[
0-9
])(?=
.*
[
a-z
])(?=
.*
[
A-Z
])(?=
.*
[
~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/])[
0-9a-zA-Z~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/]{8,16}
$/
,
// 密码必须包含字母、数字和特殊符号
strong
:
/^
(?=
.*
[
0-9
])(?=
.*
[
a-zA-Z
])(?=
.*
[
~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/])[
0-9a-zA-Z~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/]{8,16}
$/
,
// 密码必须为字母、数字和特殊符号任意两种的组合
medium
:
/^
(?![
0-9
]
+$
)(?![
a-zA-Z
]
+$
)(?![
~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/]
+$
)[
0-9a-zA-Z~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/]{8,16}
$/
,
// 密码必须包含字母和数字
weak
:
/^
(?=
.*
[
0-9
])(?=
.*
[
a-zA-Z
])[
0-9a-zA-Z~!@#$%^&*_
\-
+=`|
\\
(){}[
\]
:;"'<>,.?
/]{6,16}
$/
}
function
createPasswordVerifier
({
passwordStrength
=
'
medium
'
}
=
{})
{
return
function
(
password
)
{
const
passwordRegExp
=
passwordRules
[
passwordStrength
]
if
(
!
passwordRegExp
)
{
throw
new
Error
(
'
Invalid password strength config:
'
+
passwordStrength
)
}
const
errCode
=
ERROR
.
INVALID_PASSWORD
if
(
!
isValidString
(
password
))
{
return
{
errCode
}
}
if
(
!
passwordRegExp
.
test
(
password
))
{
return
{
errCode
:
errCode
+
'
-
'
+
passwordStrength
}
}
}
}
class
Validator
{
constructor
()
{
constructor
({
passwordStrength
=
'
medium
'
}
=
{})
{
this
.
baseValidator
=
baseValidator
this
.
customValidator
=
Object
.
create
(
null
)
this
.
mixin
(
'
password
'
,
createPasswordVerifier
({
passwordStrength
})
)
}
mixin
(
type
,
handler
)
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.test.js
浏览文件 @
57d76638
...
...
@@ -39,14 +39,14 @@ const testCaseList = [{
}
},
{
value
:
{
password
:
'
123456
'
password
:
'
123456
abc
'
},
schema
:
{
password
:
'
password
'
}
},
{
value
:
{
password
:
'
123456
'
password
:
'
123456
def
'
},
schema
:
{
password
:
'
password
'
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
57d76638
...
...
@@ -109,7 +109,9 @@ module.exports = {
})
this
.
config
=
this
.
configUtils
.
getPlatformConfig
()
this
.
validator
=
new
Validator
()
this
.
validator
=
new
Validator
({
passwordStrength
:
this
.
config
.
passwordStrength
||
'
medium
'
})
/**
* 示例:覆盖密码验证规则
*/
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
浏览文件 @
57d76638
...
...
@@ -16,6 +16,10 @@ const sentence = {
'
uni-id-password-error-exceed-limit
'
:
'
The number of password errors is excessive
'
,
'
uni-id-invalid-username
'
:
'
Invalid username
'
,
'
uni-id-invalid-password
'
:
'
invalid password
'
,
'
uni-id-invalid-password-super
'
:
'
Passwords must have 8-16 characters and contain uppercase letters, lowercase letters, numbers, and symbols.
'
,
'
uni-id-invalid-password-strong
'
:
'
Passwords must have 8-16 characters and contain letters, numbers and symbols.
'
,
'
uni-id-invalid-password-medium
'
:
'
Passwords must have 8-16 characters and contain at least two of the following: letters, numbers, and symbols.
'
,
'
uni-id-invalid-password-weak
'
:
'
Passwords must have 6-16 characters and contain letters and numbers.
'
,
'
uni-id-invalid-mobile
'
:
'
Invalid mobile phone number
'
,
'
uni-id-invalid-email
'
:
'
Invalid email address
'
,
'
uni-id-invalid-nickname
'
:
'
Invalid nickname
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
浏览文件 @
57d76638
...
...
@@ -16,6 +16,10 @@ const sentence = {
'
uni-id-password-error-exceed-limit
'
:
'
密码错误次数过多,请稍后再试
'
,
'
uni-id-invalid-username
'
:
'
用户名不合法
'
,
'
uni-id-invalid-password
'
:
'
密码不合法
'
,
'
uni-id-invalid-password-super
'
:
'
密码必须包含大小写字母、数字和特殊符号,长度8-16位
'
,
'
uni-id-invalid-password-strong
'
:
'
密码必须包含字母、数字和特殊符号,长度8-16位不合法
'
,
'
uni-id-invalid-password-medium
'
:
'
密码必须为字母、数字和特殊符号任意两种的组合,长度8-16位
'
,
'
uni-id-invalid-password-weak
'
:
'
密码必须包含字母和数字,长度6-16位
'
,
'
uni-id-invalid-mobile
'
:
'
手机号码不合法
'
,
'
uni-id-invalid-email
'
:
'
邮箱不合法
'
,
'
uni-id-invalid-nickname
'
:
'
昵称不合法
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录