diff --git a/index.js b/index.js index a72e7e6..06a96b1 100644 --- a/index.js +++ b/index.js @@ -1 +1,6 @@ -// Do work! \ No newline at end of file +// Do work! +function validatePassword(password){ +if (password.length >= 8) +return true +} +module.exports = validatePassword \ No newline at end of file diff --git a/package.json b/package.json index 21c8e3e..c38e46c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "lint": "eslint --format codeframe .", "lint:fix": "eslint --fix --format codeframe .", - "test": "mocha -w" + "test": "mocha " }, "repository": { "type": "git", diff --git a/test/index.spec.js b/test/index.spec.js index e9cf47f..fcf1185 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,5 +1,5 @@ const { expect } = require('chai') -const validatePassword = require('../index') +const validatePassword = require('../validatePassword2') describe('validatePassword', () => { it('returns true when the password meets all requirements', () => { diff --git a/validatePassword2.js b/validatePassword2.js new file mode 100644 index 0000000..d662c0c --- /dev/null +++ b/validatePassword2.js @@ -0,0 +1,29 @@ +function isLowerCase(pwd, index) { + return pwd.charCodeAt(index) >= 97 && pwd.charCodeAt(index) <= 122 + } + function isUpperCase(pwd, index) { + return pwd.charCodeAt(index) >= 65 && pwd.charCodeAt(index) <= 90 + } + function isNumeric(pwd, index) { + return !isNaN(pwd[index]) + } + function validatePassword(pwd) { + if (pwd.length < 8) return false + let upper = 0 + let lower = 0 + let numeric = 0 + let special = 0 + for (let i = 0; i < pwd.length; i++) { + if (isLowerCase(pwd, i)) { + lower++ + } else if (isUpperCase(pwd, i)) { + upper++ + } else if (isNumeric(pwd, i)) { + numeric++ + } else { + special++ + } + } + return lower > 0 && upper > 0 && numeric > 0 && special > 0 + } + module.exports = validatePassword \ No newline at end of file