Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass all 6 tests for password-validator #21

Open
wants to merge 1 commit into
base: answer
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
// Do work!



function validatePassword(password) {
if (password.length < 8) return false

const stringOfNumbers = '1234567890'
const stringOfSpecialChars = '`~!@#$%^&*()_+-=[]\\{}|;\':",./<>?'
const stringOfAlaphabet = 'abcdefghijklmnopqrstuvwxyz'

let upper = 0
let lower = 0
let numeric = 0
let special = 0

for (let i = 0; i < password.length; i++) {
if (stringOfAlaphabet.includes(password[i])) {
lower++
} else if (stringOfAlaphabet.toUpperCase().includes(password[i])) {
upper++
} else if (stringOfNumbers.includes(password[i])) {
numeric++
} else if (stringOfSpecialChars.includes(password[i])) {
special++
}
}

return lower > 0 && upper > 0 && numeric > 0 && special > 0
}

module.exports = validatePassword