mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +00:00
Validation with min length and byte validation in reset added
This commit is contained in:
parent
18193db7bf
commit
5d90c4b9e4
@ -29,10 +29,15 @@ const RESET_PASSWORD_SCHEMA = yup.object().shape({
|
|||||||
defaultMessage: 'Password must be at least 8 characters',
|
defaultMessage: 'Password must be at least 8 characters',
|
||||||
values: { min: 8 },
|
values: { min: 8 },
|
||||||
})
|
})
|
||||||
.max(70,{
|
.test(
|
||||||
id: translatedErrors.maxLength.id,
|
'required-byte-size',
|
||||||
defaultMessage: "Password should be less than 70 characters"
|
'Password must be between 8 and 70 bytes',
|
||||||
})
|
(value) => {
|
||||||
|
if (!value) return false;
|
||||||
|
const byteSize = new TextEncoder().encode(value).length;
|
||||||
|
return byteSize >= 8 && byteSize <= 70;
|
||||||
|
}
|
||||||
|
)
|
||||||
.matches(/[a-z]/, {
|
.matches(/[a-z]/, {
|
||||||
message: {
|
message: {
|
||||||
id: 'components.Input.error.contain.lowercase',
|
id: 'components.Input.error.contain.lowercase',
|
||||||
@ -114,9 +119,9 @@ const ResetPassword = () => {
|
|||||||
{isBaseQueryError(error)
|
{isBaseQueryError(error)
|
||||||
? formatAPIError(error)
|
? formatAPIError(error)
|
||||||
: formatMessage({
|
: formatMessage({
|
||||||
id: 'notification.error',
|
id: 'notification.error',
|
||||||
defaultMessage: 'An error occurred',
|
defaultMessage: 'An error occurred',
|
||||||
})}
|
})}
|
||||||
</Typography>
|
</Typography>
|
||||||
) : null}
|
) : null}
|
||||||
</Column>
|
</Column>
|
||||||
|
|||||||
@ -22,10 +22,11 @@ export const username = yup.string().min(1);
|
|||||||
|
|
||||||
export const password = yup
|
export const password = yup
|
||||||
.string()
|
.string()
|
||||||
|
.min(8)
|
||||||
.test(
|
.test(
|
||||||
'required-byte-size',
|
'required-byte-size',
|
||||||
'Password must be between 8 and 70 bytes',
|
'Password must be between 8 and 70 bytes',
|
||||||
(value:string) => {
|
(value) => {
|
||||||
if (!value) return false;
|
if (!value) return false;
|
||||||
const byteSize = new TextEncoder().encode(value).length;
|
const byteSize = new TextEncoder().encode(value).length;
|
||||||
return byteSize >= 8 && byteSize <= 70;
|
return byteSize >= 8 && byteSize <= 70;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user