Password Rule Checker

Validate a password by reporting which rules failed.

Start building, submit solution and get feedback from the community.
2Submit Solution
5 upvotes10 upvotes

Password Rule Checker

Build a small password validator. Each rule should live in its own function, and the final validator should report which rules failed.

Write these functions:

  • hasMinimumLength(password) should return true when the password has at least 8 characters.

  • hasNumber(password) should return true when the password contains at least one number.

  • hasUppercaseLetter(password) should return true when the password contains at least one uppercase letter.

  • getFailedRules(password) should return an array of missing rule names.

  • validatePassword(password) should return an object with valid and failedRules.

Sample checks:

js
console.log(validatePassword('hello'));console.log(validatePassword('Hello123'));console.log(validatePassword('hello123'));console.log(validatePassword('HELLOABC'));

Expected output:

txt
{ valid: false, failedRules: ["minimum length", "number", "uppercase letter"] }{ valid: true, failedRules: [] }{ valid: false, failedRules: ["uppercase letter"] }{ valid: false, failedRules: ["number"] }

Use "minimum length", "number", and "uppercase letter" as the failed rule names.

Join the Community

roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Rank  out of 28M!

361K

GitHub Stars

Star us on GitHub
Help us reach #1

+90k every month

+2.1M

Registered Users

Register yourself
Commit to your growth

+2k every month

49K

Discord Members

Join on Discord
Join the community

Roadmaps Best Practices Guides Videos FAQs YouTube

roadmap.sh by @kamrify

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.