Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito Password Regex - Specific to AWS Cognito [duplicate]

Can someone give me the regex to match a valid AWS Cognito password - with numbers, special characters (their list), lower and upper case letters

The AWS Cognito default length limit is 6 characters and has it's own list of special characters

Note that the AWS Congito password regex is specific to AWS Congnito - not just a general password regex.

like image 603
Jonathan Irwin Avatar asked Nov 28 '22 06:11

Jonathan Irwin


2 Answers

Updated Answer - September 2022


/^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\^$*.[\]{}()?"!@#%&/\\,><':;|_~`=+\- ])[A-Za-z0-9^$*.[\]{}()?"!@#%&/\\,><':;|_~`=+\- ]{8,256}$/

Explanation

  • / Indicates the start of a regular expression.
  • ^ Beginning. Matches the beginning of the string.
  • (?=.*[a-z]) Requires lowercase letters.
  • (?=.*[A-Z]) Requires uppercase letters.
  • (?=.*[0-9]) Requires numbers.
  • (?=.*[\^$*.[\]{}()?"!@#%&/\\,><':;|_~`=+\- ]) Requires at least one special character from the specified set. "The space character is treated as a special character." AWS Cognito
  • [A-Za-z0-9^$*.[\]{}()?"!@#%&/\\,><':;|_~`=+\- ]{8,256} Minimum 8 characters from the allowed set, maximum 256 characters.
  • $ End. Matches the end of the string.
  • / Indicates the end of a regular expression.

The minimum character limit defaults to 8 but can be customised to a value between 6 and 99. The full length of a password however is limited to 256 characters (not 99).

Interactive Example

  • regexr.com/6u92q (fork of an earlier example by @jonathan-irwin)
like image 60
Jonathan Irwin Avatar answered Dec 04 '22 04:12

Jonathan Irwin


the Regex formula for Swift 5 is

"(.*[()!@^$*.?\\-@#%&\":;|><'_~`+=\\[\\],{}])"
like image 24
mattyU Avatar answered Dec 04 '22 03:12

mattyU