A small command-line password validator written in Node.js.
Prompts the user for a password and keeps asking until the input satisfies all of the following rules:
- At least 8 characters long
- Contains at least one uppercase letter (
A–Z) - Contains at least one number (
0–9)
Validation is done character-by-character inside a for loop, driven by a
do...while so the prompt always runs at least once. When the input passes,
the program prints Password accepted. and exits.
- Node.js (any modern LTS version)
- npm (ships with Node)
npm installThis pulls in the single dependency, readline-sync,
which provides synchronous terminal input.
node index.jsYou will be prompted:
Enter a password:
Type a password and press Enter. If it fails any rule, the program
lists which rules failed and prompts again. On success it prints
Password accepted. and exits.
Enter a password: hello
Password does not meet the requirements. Try again.
- Must be at least 8 characters long.
- Must contain at least one uppercase letter.
- Must contain at least one number.
Enter a password: password1
Password does not meet the requirements. Try again.
- Must contain at least one uppercase letter.
Enter a password: Hunter22
Password accepted.