Sorry for repeating the question of others. I have looked at those answers but still struggling to accomplish what i need.
I want to keep trying my password generator function until it gives me one which has a symbol, a number and a upper case letter in it.
Can you help?
while (true) {
let trialPassword = randomPassGen(10)
trialPassword.forEach((letter)=>{
if (!upperLetters.includes(letter)){
return
} else if (!symbols.includes(letter)) {
return
} else if (!numbers.includes(letter)) {
return
} else {
break
}
})
console.log(trialPassword)
}
EDIT: here's the full code for my password generator. Trying this time with a for loop but still no luck. Thanks all!
const upperLetters = [
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'
]
const lowerLetters = []
// build lowerLetters from upper skipping lowecase L which could be seen as a 1
upperLetters.forEach((letter)=>{
if(letter !== 'L'){
lowerLetters.push(letter.toLowerCase())
}
})
// skips letter l
const numbers = [0,1,2,3,4,5,6,7,8,9]
const symbols = [
'!', '@', ';', ':', '$', '£', '#', '[', ']', '?', '<', '>'
]
const allChars = []
symbols.forEach((sym)=>{
allChars.push(sym)
})
numbers.forEach((num)=>{
allChars.push(num)
})
lowerLetters.forEach((lowLet)=>{
allChars.push(lowLet)
})
upperLetters.forEach((upLet)=>{
allChars.push(upLet)
})
const randomPassGen = (passLength) => {
passArr = []
for (let i = 0; i <= passLength; i++) {
let r = Math.floor(Math.random() * allChars.length);
passArr.push(allChars[r])
}
return passArr
}
while (true) {
let trialPassword = randomPassGen(chosenLength)
for (let i = 0; i <=trialPassword.length; i++){
let l = trialPassword[i]
if(!upperLetters.includes(l)){
continue
} else if (!symbols.includes(l)){
continue
} else if (!numbers.includes(l)){
continue
} else {
console.log(trialPassword)
break
}
}
}