Refine password validation

pull/6804/head
Ryan Wang 2024-10-10 10:43:20 +08:00
parent d6df340fe4
commit d7aba83485
7 changed files with 27 additions and 14 deletions

View File

@ -12,6 +12,7 @@ import { Toast, VButton, VModal, VSpace } from "@halo-dev/components";
import { setFocus } from "@/formkit/utils/focus";
import { useQueryClient } from "@tanstack/vue-query";
import { useI18n } from "vue-i18n";
import { PASSWORD_REGEX } from "@/constants/regex";
const { t } = useI18n();
const queryClient = useQueryClient();
@ -112,9 +113,13 @@ const handleCreateUser = async () => {
:label="$t('core.user.change_password_modal.fields.new_password.label')"
type="password"
name="password"
validation="required:trim|length:5,100|matches:/^\S.*\S$/"
:validation="[
['required'],
['length', 5, 257],
['matches', PASSWORD_REGEX],
]"
:validation-messages="{
matches: $t('core.formkit.validation.trim'),
matches: $t('core.formkit.validation.password'),
}"
></FormKit>
<FormKit

View File

@ -1,5 +1,6 @@
<script lang="ts" setup>
import SubmitButton from "@/components/button/SubmitButton.vue";
import { PASSWORD_REGEX } from "@/constants/regex";
import { setFocus } from "@/formkit/utils/focus";
import type { User } from "@halo-dev/api-client";
import { consoleApiClient } from "@halo-dev/api-client";
@ -81,9 +82,13 @@ const handleChangePassword = async () => {
:label="$t('core.user.change_password_modal.fields.new_password.label')"
name="password"
type="password"
validation="required:trim|length:5,100|matches:/^\S.*\S$/"
:validation="[
['required'],
['length', 5, 257],
['matches', PASSWORD_REGEX],
]"
:validation-messages="{
matches: $t('core.formkit.validation.trim'),
matches: $t('core.formkit.validation.password'),
}"
></FormKit>
<FormKit
@ -92,10 +97,7 @@ const handleChangePassword = async () => {
"
name="password_confirm"
type="password"
validation="confirm|required:trim|length:5,100|matches:/^\S.*\S$/"
:validation-messages="{
matches: $t('core.formkit.validation.trim'),
}"
validation="confirm|required"
></FormKit>
</FormKit>
<template #footer>

View File

@ -0,0 +1 @@
export const PASSWORD_REGEX = /^[A-Za-z0-9!@#$%^&*]+$/;

View File

@ -1664,6 +1664,7 @@ core:
creation_label: Create {text} tag
validation:
trim: Please remove the leading and trailing spaces
password: "The password can only use uppercase and lowercase letters (A-Z, a-z), numbers (0-9), and the following special characters: !{'@'}#$%^&*"
verification_form:
no_action_defined: "{label} interface not defined"
verify_success: "{label} successful"

View File

@ -1557,6 +1557,7 @@ core:
creation_label: 创建 {text} 标签
validation:
trim: 不能以空格开头或结尾
password: "密码只能使用大小写字母 (A-Z, a-z)、数字 (0-9),以及以下特殊字符: !{'@'}#$%^&*"
verification_form:
no_action_defined: 未定义{label}接口
verify_success: "{label}成功"

View File

@ -1535,6 +1535,7 @@ core:
creation_label: 創建 {text} 標籤
validation:
trim: 不能以空格開頭或結尾
password: "密碼只能使用大小寫字母 (A-Z, a-z)、數字 (0-9),以及以下特殊字符: !{'@'}#$%^&*"
verification_form:
no_action_defined: 未定義{label}介面
verify_success: "{label}成功"

View File

@ -1,5 +1,6 @@
<script lang="ts" setup>
import SubmitButton from "@/components/button/SubmitButton.vue";
import { PASSWORD_REGEX } from "@/constants/regex";
import { setFocus } from "@/formkit/utils/focus";
import { consoleApiClient } from "@halo-dev/api-client";
import { VButton, VModal, VSpace } from "@halo-dev/components";
@ -81,9 +82,13 @@ const handleChangePassword = async () => {
"
name="password"
type="password"
validation="required:trim|length:5,100|matches:/^\S.*\S$/"
:validation="[
['required'],
['length', 5, 257],
['matches', PASSWORD_REGEX],
]"
:validation-messages="{
matches: $t('core.formkit.validation.trim'),
matches: $t('core.formkit.validation.password'),
}"
></FormKit>
<FormKit
@ -94,10 +99,7 @@ const handleChangePassword = async () => {
"
name="password_confirm"
type="password"
validation="confirm|required:trim|length:5,100|matches:/^\S.*\S$/"
:validation-messages="{
matches: $t('core.formkit.validation.trim'),
}"
validation="confirm|required"
></FormKit>
</FormKit>
<template #footer>