Skip to content
Open
Show file tree
Hide file tree
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
30 changes: 29 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
// Do work!
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()

if (upperCase === password || lowerCase === password) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks clever. Are you able to confirm if this is checking correctly.
It reads as though it is checking for an all uppercase or or lowercase password having been passed in.
We need it to validate that there is one upper and one lower letter only.
Maybe it is solving this but from looking closely that is the curiosity I have.

return false
} else {
for (let index = 0; index < password.length; index++) {
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
}
}
}
}

return isSpecial && isNumeric
}
module.exports = validatePassword
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"chai": "^4.2.0",
"eslint": "^6.8.0",
"mocha": "^7.1.2"
}
},
"dependencies": {}
}