Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
e513946d
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e513946d
编写于
6月 23, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: passwordErrorLimit
上级
69d0074a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
42 addition
and
0 deletion
+42
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
+1
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
...uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
+1
-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
+1
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
...ages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
+39
-0
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
浏览文件 @
e513946d
...
...
@@ -8,6 +8,7 @@ const ERROR = {
ACCOUNT_CLOSED
:
'
uni-id-account-closed
'
,
CAPTCHA_REQUIRED
:
'
uni-id-captcha-required
'
,
PASSWORD_ERROR
:
'
uni-id-password-error
'
,
PASSWORD_ERROR_EXCEED_LIMIT
:
'
uni-id-password-error-exceed-limit
'
,
INVALID_USERNAME
:
'
uni-id-invalid-username
'
,
INVALID_PASSWORD
:
'
uni-id-invalid-password
'
,
INVALID_MOBILE
:
'
uni-id-invalid-mobile
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
浏览文件 @
e513946d
...
...
@@ -13,6 +13,7 @@ const sentence = {
'
uni-id-account-closed
'
:
'
Account has been closed
'
,
'
uni-id-captcha-required
'
:
'
Captcha required
'
,
'
uni-id-password-error
'
:
'
Username or password error
'
,
'
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-mobile
'
:
'
Invalid mobile phone number
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
浏览文件 @
e513946d
...
...
@@ -13,6 +13,7 @@ const sentence = {
'
uni-id-account-closed
'
:
'
此账号已注销
'
,
'
uni-id-captcha-required
'
:
'
请输入图形验证码
'
,
'
uni-id-password-error
'
:
'
用户名或密码错误
'
,
'
uni-id-password-error-exceed-limit
'
:
'
密码错误次数过多,请稍后再试
'
,
'
uni-id-invalid-username
'
:
'
用户名不合法
'
,
'
uni-id-invalid-password
'
:
'
密码不合法
'
,
'
uni-id-invalid-mobile
'
:
'
手机号码不合法
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
浏览文件 @
e513946d
...
...
@@ -57,9 +57,27 @@ async function preLoginWithPassword (params = {}) {
}
=
params
try
{
const
userRecord
=
await
realPreLogin
.
call
(
this
,
params
)
const
{
passwordErrorLimit
,
passwordErrorRetryTime
}
=
this
.
config
const
{
clientIP
}
=
this
.
getClientInfo
()
// 根据ip地址,密码错误次数过多,锁定登录
let
loginIPLimit
=
userRecord
.
login_ip_limit
||
[]
// 清理无用记录
loginIPLimit
=
loginIPLimit
.
filter
(
item
=>
item
.
last_error_time
>
Date
.
now
()
-
passwordErrorRetryTime
*
1000
)
let
currentIPLimit
=
loginIPLimit
.
find
(
item
=>
item
.
ip
===
clientIP
)
if
(
currentIPLimit
&&
currentIPLimit
.
error_times
>=
passwordErrorLimit
)
{
throw
{
errCode
:
ERROR
.
PASSWORD_ERROR_EXCEED_LIMIT
}
}
const
passwordUtils
=
new
PasswordUtils
({
passwordSecret
:
this
.
config
.
passwordSecret
})
const
{
success
:
checkPasswordSuccess
,
refreshPasswordInfo
...
...
@@ -69,6 +87,21 @@ async function preLoginWithPassword (params = {}) {
passwordSecretVersion
:
userRecord
.
password_secret_version
})
if
(
!
checkPasswordSuccess
)
{
// 更新用户ip对应的密码错误记录
if
(
!
currentIPLimit
)
{
currentIPLimit
=
{
ip
:
clientIP
,
error_times
:
1
,
last_error_time
:
Date
.
now
()
}
loginIPLimit
.
push
(
currentIPLimit
)
}
else
{
currentIPLimit
.
error_times
++
currentIPLimit
.
last_error_time
=
Date
.
now
()
}
await
userCollection
.
doc
(
userRecord
.
_id
).
update
({
login_ip_limit
:
loginIPLimit
})
throw
{
errCode
:
ERROR
.
PASSWORD_ERROR
}
...
...
@@ -78,6 +111,12 @@ async function preLoginWithPassword (params = {}) {
extraData
.
password
=
refreshPasswordInfo
.
passwordHash
extraData
.
password_secret_version
=
refreshPasswordInfo
.
version
}
const
currentIPLimitIndex
=
loginIPLimit
.
indexOf
(
currentIPLimit
)
if
(
currentIPLimitIndex
>
-
1
)
{
loginIPLimit
.
splice
(
currentIPLimitIndex
,
1
)
}
extraData
.
login_ip_limit
=
loginIPLimit
return
{
user
:
userRecord
,
extraData
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录