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

ASUB-8899 Match password sign up #2268

Merged
Merged
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
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
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);
});
});
Loading