I am trying to create a function where it verifies the strength of a password. I've seen a few examples online for other langauges but not for javascript.
- password cannot be null
- 8 characters
- 1 uppercase letter
- 1 lowercase letter
- 1 number
I've noticed some people using Regex but is there any other way for this? I've tried the below which gets me up to verifying the caps letters but doesnt verify lowercase or numbers.
const passwordVerifier = (password) => {
let result = ''
let upperCase = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
let lowerCase = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
//The password should not be null
if(password !== null){
//The password should be larger than 8 chars
if(password.length >= 8 ){
//The password should have one uppercase/ lowercase letter
for(let i = 0; i <= password.length; i++){
if(upperCase.indexOf(password[i]) >= 1 && lowerCase.indexOf(password[i]) >= 1){
result += 'Strong Password'
return result
}
} result += 'Must have caps and lowcaps'
return result
} result += 'Must have 8 characters'
return result
}
result += 'Password cannot be null'
return result
}
console.log(passwordVerifier("Password123"))
Also how can I get it to check if it has numbers?