Skip to content

Commit

Permalink
feat: check old password for admin-review修改 #811
Browse files Browse the repository at this point in the history
  • Loading branch information
Canway-shiisa committed Dec 13, 2022
1 parent 3425672 commit 8d9c13e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/api/bkuser_core/config/common/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

# 允许原始密码校验错误次数
ALLOW_OLD_PASSWORD_ERROR_TIME = 3
# 重置密码时对原始密码校验超限是否锁定
ENABLE_LOCK = env.bool("ENABLE_LOCK", default=False)

# 最大密码长度(明文)
PASSWORD_MAX_LENGTH = 32
# 重复密码最大历史数量
Expand Down Expand Up @@ -89,8 +92,8 @@
# 登录次数统计时间周期, 默认为一个月
LOGIN_RECORD_COUNT_SECONDS = env.int("LOGIN_RECORD_COUNT_SECONDS", default=60 * 60 * 24 * 30)

# 重置密码次数统计时间周期, 默认为一个月
RESET_PASSWORD_RECORD_COUNT_SECONDS = env.int("RESET_PASSWORD_RECORD_COUNT_SECONDS", default=60 * 60 * 24 * 30)
# 重置密码次数统计时间周期, 默认为十分钟
RESET_PASSWORD_RECORD_COUNT_SECONDS = env.int("RESET_PASSWORD_RECORD_COUNT_SECONDS", default=60 * 10)

# sync, 用户管理本身做业务 HTTP API 数据源, 可以被另一个用户管理同步过去
# 复用 API, 接口参数中存在 SYNC_API_PARAM 时, 以sync的接口协议返回
Expand Down
6 changes: 3 additions & 3 deletions src/api/bkuser_core/profiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ def check_old_password(instance: "Profile", old_password: str, request: "Request
operator_obj=instance,
request=request,
status=OperationStatus.FAILED.value,
extra_info={"failed_info": failed_reason.get_choices()},
extra_info={"failed_info": failed_reason.get_choice_label(failed_reason.value)},
)

if instance.bad_old_password_check_cnt >= settings.ALLOW_OLD_PASSWORD_ERROR_TIME:
# 校验失败次数超过配置次数会对用户进行锁定
if instance.bad_old_password_check_cnt >= settings.ALLOW_OLD_PASSWORD_ERROR_TIME and settings.ENABLE_LOCK:
# 校验失败次数超过配置次数并且配置锁定则对用户进行锁定
raw_profile.status = ProfileStatus.LOCKED.value
raw_profile.save()
create_general_log(
Expand Down

0 comments on commit 8d9c13e

Please sign in to comment.