AWS Cognito Password Regex

Jonathan Irwin
2 min readJun 29, 2020

Let your users know if they meet your password requirements

Photo by Chris Barbalis on Unsplash

If you are using AWS Cognito there will come a time when you require a regular expression to check that users meet your password strength requirements

AWS Cognito Password Strength Options

Solution

/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\^$*.\[\]{}\(\)?\-“!@#%&/,><\’:;|_~`])\S{8,99}$/

That regex covers the default case where all boxes are selected. If you want to adjust the selection see the explanation below on how to make it work for your use-case.

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 special characters (only the special characters listed by AWS Cognito).
  • \S Whitespace (space, tab, carriage return) not allowed
  • {8,99} Minimum 8 characters, maximum 99 characters
  • $ End. Matches the end of the string.
  • / Close.

Links

You can find an interactive example here

You can find a Stack Overflow question on the subject here

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Jonathan Irwin
Jonathan Irwin

Written by Jonathan Irwin

I scream.. You scream.. The police come.. It’s awkward..

Responses (1)

Write a response

Thanks for the post! I have a question regarding this: Does Cognito allow users to use accent letters in the password? For example, something like Test123äü!

--