From 934050213d7113ec4f06bda794d9051dc315e678 Mon Sep 17 00:00:00 2001 From: mvrcusj Date: Tue, 7 Jul 2020 14:01:48 -0400 Subject: [PATCH 1/3] Pass all tests except for the special character requirement test --- index.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a72e7e6..ac9bdb1 100644 --- a/index.js +++ b/index.js @@ -1 +1,28 @@ -// Do work! \ No newline at end of file +/* eslint-disable nonblock-statement-body-position */ +function validatePassword(password) { + let allRequirementsMet = false + let specCharacters = '!"#$%&/' / '()*+,-.' + + // Determine if the password length is more than or equal to 8 then.. + if (password.length >= 8) { + // Using ASCII index and charCodeAt method (thanks to Jkearns!) + // Test further requirements + // Test for uppercase characters + for (let i = 0; i < password.length; i++) { + if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) + // Test for lowercase characters + for (let i = 0; i < password.length; i++) { + if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) + // Test for numeric value + for (let i = 0; i < password.length; i++) { + if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) + allRequirementsMet = true + } + } + } + } + + return allRequirementsMet +} + +module.exports = validatePassword From 4db97b8bb4b604ca6064711fd578fba80d4865c4 Mon Sep 17 00:00:00 2001 From: mvrcusj Date: Wed, 8 Jul 2020 13:39:02 -0400 Subject: [PATCH 2/3] Pass all tests for a valid password --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ac9bdb1..4a4798d 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,11 @@ function validatePassword(password) { // Test for numeric value for (let i = 0; i < password.length; i++) { if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) - allRequirementsMet = true + // Test for special characters + for (let i = 0; i < password.length; i++) { + if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 46) + allRequirementsMet = true + } } } } @@ -24,5 +28,4 @@ function validatePassword(password) { return allRequirementsMet } - module.exports = validatePassword From 262b6044542cc4c67573cd187947172da09a6eed Mon Sep 17 00:00:00 2001 From: mvrcusj Date: Mon, 13 Jul 2020 19:34:57 -0400 Subject: [PATCH 3/3] Resolve excessive looping --- index.js | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 4a4798d..08ada88 100644 --- a/index.js +++ b/index.js @@ -1,31 +1,36 @@ /* eslint-disable nonblock-statement-body-position */ function validatePassword(password) { - let allRequirementsMet = false - let specCharacters = '!"#$%&/' / '()*+,-.' + let requirementsMet = true // Determine if the password length is more than or equal to 8 then.. if (password.length >= 8) { + requirementsMet = true // Using ASCII index and charCodeAt method (thanks to Jkearns!) - // Test further requirements - // Test for uppercase characters - for (let i = 0; i < password.length; i++) { - if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) + } else { requirementsMet = false } + // Test further requirements + // Test for uppercase characters + for (let i = 0; i < password.length; i++) { + if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) { + requirementsMet = true // Test for lowercase characters - for (let i = 0; i < password.length; i++) { - if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) - // Test for numeric value - for (let i = 0; i < password.length; i++) { - if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) - // Test for special characters - for (let i = 0; i < password.length; i++) { - if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 46) - allRequirementsMet = true - } - } - } - } - } + } else { requirementsMet = false } + if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) { + requirementsMet = true + // Test for numeric value + } else { requirementsMet = false } + if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) { + requirementsMet = true + // Test for special characters + } else { requirementsMet = false } + if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 47) { + requirementsMet = true + } else { requirementsMet = false } + requirementsMet = true - return allRequirementsMet + requirementsMet = false } + + return requirementsMet } + + module.exports = validatePassword