Last active
July 4, 2022 01:08
-
-
Save andrei-coelho/fe520071b1dbb9a429d97eb295139892 to your computer and use it in GitHub Desktop.
function checks if the password is strong
This file contains 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
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