Created
September 12, 2019 11:39
-
-
Save andreasvirkus/1facbfe6fb8f4cac0daea82f96d65fe7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Medium-strength regex checks if the password contains 2 of: | |
* - lowercase alphabetical char | |
* - uppercase alphabetical char | |
* - numerical character | |
* - minimum of 6 characters | |
* | |
* Strong-strength regex checks if the password contains all of: | |
* - lowercase alphabetical char | |
* - uppercase alphabetical char | |
* - numerical character | |
* - minimum of 8 characters | |
* - a special character symbol | |
*/ | |
export const mediumRegex = new RegExp('^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})') | |
export const strongRegex = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})') | |
export const passwordStrength = () => strongRegex.test(this.password) | |
? 2 | |
: mediumRegex.test(this.password) | |
? 1 | |
: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment