Skip to content

Commit

Permalink
ASUB-8899 Match password sign up (#2268)
Browse files Browse the repository at this point in the history
* match password sign up
* solving issue reported on ACS-32025
  • Loading branch information
LauraPinilla authored Nov 8, 2024
1 parent 7bf9d27 commit 735d2ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const FormPasswordConfirm = ({
}) => {
const [password, setPassword] = useState("");

const escapeForHtmlPattern = (value) =>{
const specialChars = /[.*+?^${}()|[\]\\]/g;
const newValue = value.replace(specialChars, '\\$&');
return newValue;
};

const fieldParameters = {
...(autoComplete ? { autoComplete } : {}),
...(placeholder ? { placeholder } : {}),
Expand Down Expand Up @@ -55,7 +61,7 @@ const FormPasswordConfirm = ({
name={`${name}-confirmation`}
required
type="password"
validationPattern={`^${password}$`}
validationPattern={escapeForHtmlPattern(password)}
className={className}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function AppleSignIn({ customButtons, socialSignOnIn, className, oidcClients = [
const phrases = usePhrases();
const { Identity } = useIdentity();

const appleOIDCClient = oidcClients.find((oidcClient) => {
const appleOIDCClient = oidcClients && oidcClients.find((oidcClient) => {
const parsedClientId = oidcClient.clientId.split(';')[0];

return oidcClient.protocol === 'Apple' && parsedClientId === appleClientId;
Expand Down
9 changes: 7 additions & 2 deletions blocks/identity-block/utils/validate-password-pattern.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const SPECIAL_CHARACTERS_ALLOWED = "@$!%*?&";
const SPECIAL_CHARACTERS_ALLOWED =
".@$!%*+?&#<=>^:;,-" +
"\\/\\(\\)\\{\\}\\[\\]\\|\\`\\\\" +
"~_" +
'"' +
"'";

// positive lookahead (?= )
// with a non-capturing group within (?: )
Expand All @@ -12,7 +17,7 @@ const validatePasswordPattern = (
pwMinLength,
pwPwNumbers,
pwSpecialCharacters,
pwUppercase
pwUppercase,
) =>
`(?=(?:.*[a-z]){${pwLowercase},})(?=(?:.*[A-Z]){${pwUppercase},})(?=(?:.*\\d){${pwPwNumbers},})(?=(?:.*[${SPECIAL_CHARACTERS_ALLOWED}]){${pwSpecialCharacters},}).{${pwMinLength},}`;

Expand Down
7 changes: 4 additions & 3 deletions blocks/identity-block/utils/validate-password-pattern.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ describe("Validate Password", () => {
it("Takes matching special characters", () => {
const pattern = new RegExp(validatePasswordPattern(0, 1, 0, 7, 0));

expect(pattern.test("@$!%*?&")).toBe(true);
expect(pattern.test("---------")).toBe(false);
expect(pattern.test("^^^^^^^^^^^^^^^^^^^^^^^")).toBe(false);
expect(pattern.test("@$!%*?&")).toBe(true);
expect(pattern.test("---")).toBe(false);
expect(pattern.test("---------")).toBe(true);
expect(pattern.test("^^^^^^^^^^^^^^^^^^^^^^^")).toBe(true);
});
});

0 comments on commit 735d2ed

Please sign in to comment.