Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use password regex [DHIS2-15704] #1469

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2025-01-07T11:04:56.155Z\n"
"PO-Revision-Date: 2025-01-07T11:04:56.155Z\n"
"POT-Creation-Date: 2025-01-09T11:55:44.018Z\n"
"PO-Revision-Date: 2025-01-09T11:55:44.019Z\n"

msgid "Never"
msgstr "Never"
Expand Down Expand Up @@ -156,11 +156,13 @@ msgid "New password"
msgstr "New password"

msgid ""
"Password should be at least 8 characters with at least 1 digit, 1 uppercase "
"letter and 1 special character"
"Password should be between {{minPasswordLength}} and {{maxPasswordLength}} "
"characters long, with at least one lowercase character, one uppercase "
"character, one number, and one special character."
msgstr ""
"Password should be at least 8 characters with at least 1 digit, 1 uppercase "
"letter and 1 special character"
"Password should be between {{minPasswordLength}} and {{maxPasswordLength}} "
"characters long, with at least one lowercase character, one uppercase "
"character, one number, and one special character."

msgid "Repeat new password"
msgstr "Repeat new password"
Expand Down
15 changes: 12 additions & 3 deletions src/account/AccountEditor.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, { Component } from 'react'
import appActions from '../app.actions.js'
import i18n from '../locales/index.js'
import accountActions from './account.actions.js'
import isValidPassword from './isValidPassword.js'

const styles = {
notification: {
Expand Down Expand Up @@ -96,8 +95,16 @@ class AccountEditor extends Component {
this.setState({ [e]: v })
}

validatePassword = (val, regEx) => (!val ? true : regEx.test(val))

render() {
const usesOpenIdConnect = this.context.d2.currentUser.externalAuth
const {
minPasswordLength,
maxPasswordLength,
passwordValidationPattern = '^(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_])[A-Za-z\\d\\W_]{8,32}$',
} = this.context.d2.system.settings.settings
const passwordRegEx = new RegExp(passwordValidationPattern)
const fields = [
{
name: 'username',
Expand Down Expand Up @@ -142,9 +149,11 @@ class AccountEditor extends Component {
},
validators: [
{
validator: isValidPassword,
validator: (val) =>
this.validatePassword(val, passwordRegEx),
message: i18n.t(
'Password should be at least 8 characters with at least 1 digit, 1 uppercase letter and 1 special character'
'Password should be between {{minPasswordLength}} and {{maxPasswordLength}} characters long, with at least one lowercase character, one uppercase character, one number, and one special character.',
{ minPasswordLength, maxPasswordLength }
),
},
],
Expand Down
23 changes: 0 additions & 23 deletions src/account/isValidPassword.js

This file was deleted.

Loading