From dd3cbdf09b712de94b8ba6aceb78ea4d30276278 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 9 Jul 2020 15:15:28 -0400 Subject: [PATCH] Pass all 6 tests for password-validator --- index.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a72e7e6..49ebea6 100644 --- a/index.js +++ b/index.js @@ -1 +1,31 @@ -// Do work! \ No newline at end of file + + + +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 \ No newline at end of file