Skip to content
Open
Changes from 2 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
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
// Do work!
/* eslint-disable nonblock-statement-body-position */
Copy link
Member

Choose a reason for hiding this comment

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

This solution is very close to the solution @erick-pacheco has. Did you guys work together on this work?

function validatePassword(password) {
Copy link
Member

Choose a reason for hiding this comment

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

Formatting is a bit tough to read.

In VS Code, you can use the formatter. Menu > View > Command Palette. Type in "Format document"

function validatePassword(password) {
  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!)
  } 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
    } 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

    requirementsMet = false
  }

  return requirementsMet
}

module.exports = validatePassword

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
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times from this outer loop.

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
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times x 10 x 10 in this deeply nested inner loop.

We are now looping 1000 times. We are looping the same loop within itself.

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++) {
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times x 10 x 10 x 10 in this most deeply nested inner loop.

We are now looping 10,000 times. We are looping the same loop within itself.

Way more looping than needed. We can fix this so it loops only in the outer loop. 10x is all that the loop should need to run. There is an extra 9,990 loops happening here.

if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 46)
allRequirementsMet = true
}
}
}
}
}

return allRequirementsMet
}
module.exports = validatePassword