From 92dcaf1d1b2bfa087aaa7f55fa3c89327be0256e Mon Sep 17 00:00:00 2001 From: rock43053 Date: Tue, 7 Jul 2020 18:25:25 -0400 Subject: [PATCH 1/2] couldnt figure out last 2 checks --- index.js | 20 +++++++++++++++++++- package.json | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a72e7e6..65cf896 100644 --- a/index.js +++ b/index.js @@ -1 +1,19 @@ -// Do work! \ No newline at end of file +function validatePassword(password) { + if (password.length >= 8) { // if the password length is 8 or more then do code after + let upperCase = password.toUpperCase() + let lowerCase = password.toLowerCase() + + if (upperCase === password || lowerCase === password) { + return false + } else { + for (let index = 0; index < password.length; index++) { + if (password.charCodeAt(index) >= 32 && password.charCodeAt(index) <= 47 || password.charCodeAt(index) >= 58 && password.charCodeAt(index) <= 64 || password.charCodeAt(index) >= 91 && password.charCodeAt(index) <= 96 || password.charCodeAt(index) >= 123 && password.charCodeAt(index) <= 126) { + return true + } + } + } + } else { + return false + } +} +module.exports = validatePassword diff --git a/package.json b/package.json index 21c8e3e..66e0d86 100644 --- a/package.json +++ b/package.json @@ -22,5 +22,6 @@ "chai": "^4.2.0", "eslint": "^6.8.0", "mocha": "^7.1.2" - } + }, + "dependencies": {} } From 888c8e98ebe8a300475df51e6ad93b46c77b252d Mon Sep 17 00:00:00 2001 From: rock43053 Date: Wed, 8 Jul 2020 21:16:59 -0400 Subject: [PATCH 2/2] HW Fully Completed --- index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 65cf896..0233726 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,8 @@ function validatePassword(password) { + let isSpecial = false + let isNumeric = false + const stringOfNums = '0123456789' + if (password.length >= 8) { // if the password length is 8 or more then do code after let upperCase = password.toUpperCase() let lowerCase = password.toLowerCase() @@ -7,13 +11,19 @@ function validatePassword(password) { return false } else { for (let index = 0; index < password.length; index++) { - if (password.charCodeAt(index) >= 32 && password.charCodeAt(index) <= 47 || password.charCodeAt(index) >= 58 && password.charCodeAt(index) <= 64 || password.charCodeAt(index) >= 91 && password.charCodeAt(index) <= 96 || password.charCodeAt(index) >= 123 && password.charCodeAt(index) <= 126) { - return true + if (password.charCodeAt(index) >= 33 && password.charCodeAt(index) <= 47 || + password.charCodeAt(index) >= 58 && password.charCodeAt(index) <= 64 || + password.charCodeAt(index) >= 91 && password.charCodeAt(index) <= 96 || + password.charCodeAt(index) >= 123 && password.charCodeAt(index) <= 126) { + isSpecial = true + } + if (stringOfNums.includes(password[index])) { + isNumeric = true } } } - } else { - return false } + + return isSpecial && isNumeric } module.exports = validatePassword