Skip to content

Instantly share code, notes, and snippets.

@andrei-coelho
Last active July 4, 2022 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrei-coelho/fe520071b1dbb9a429d97eb295139892 to your computer and use it in GitHub Desktop.
Save andrei-coelho/fe520071b1dbb9a429d97eb295139892 to your computer and use it in GitHub Desktop.
function checks if the password is strong
function is_strong_pass(pass){
if(pass.length < 6) return false;
// chars: 1 especial - 1 number - 1 uppercase - 1 lowercase
let re = new RegExp(/([^\w]+)|(\d+)|([A-Z]+)|([a-z]+)/gm);
const match = pass.matchAll(re);
const groups = [false, false, false, false]
const els = Array.from(match);
for(let i = 0; i < els.length; i++){
let el = els[i];
for(let x = 1; x < 5; x++){
if(el[x] !== undefined) {
groups[x-1] = true;
break;
}
}
}
return groups.every(v => v === true)
}
console.log(is_strong_pass("Ma#t3l4@"))
console.log(is_strong_pass("abc123"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment