Command-Line Password Generator Tool
Build a PHP command-line tool that creates strong random passwords: choose the length and which kinds of characters to include (lowercase, uppercase, digits and symbols), generate one or many at once, and be sure every password contains at least one character of each chosen kind. Randomness comes from random_int, PHP's cryptographically secure generator, never from rand or mt_rand. It also shows each password's strength in bits of entropy. It's a good first PHP project outside the browser: you'll learn running PHP scripts from the terminal, reading options with getopt, secure randomness, working with strings and arrays, validating input, and testing with PHPUnit.
- Estimate
- ~4.5h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
PHP CLI
Project roadmap
- 01
Set up the script
~0.5hCreate passgen.php with a #!/usr/bin/env php line so it can run directly, and read options with getopt: --length (default 16), --count (default 1), --no-upper, --no-digits, --no-symbols, --exclude-similar and --help. Print the parsed options for now. Done when: ./passgen.php --length 20 prints the options.
- 02
Generate secure passwords
~1hBuild the character pool from the chosen kinds, and pick each character with random_int(0, count - 1) so every character is equally likely. Explain in a comment why rand and mt_rand must not be used for passwords. With --exclude-similar, leave out characters that look alike (such as l, 1, I, O and 0). Done when: passwords of the chosen length are generated from the right characters.
- 03
Validate the options
~0.5hCheck the length is between 8 and 128 and the count between 1 and 100, and that at least one kind of character is left, printing a clear message and exiting with code 1 otherwise. Done when: invalid options print helpful messages.
- 04
Guarantee each kind
~1hMake sure every password contains at least one character of each chosen kind: pick one from each kind first, fill the rest from the whole pool, then shuffle securely with a Fisher-Yates shuffle using random_int (not str_shuffle, which isn't secure). Show the entropy in bits (length × log2 of the pool size) with a label such as strong. Done when: every generated password contains each chosen kind.
- 05
Polish the output and test
~1.5hPrint one password per line (with the strength next to it unless --quiet is given, which is handy for scripts), and a --help message with examples. Install PHPUnit with Composer and test: lengths, excluded kinds never appearing, every chosen kind present, similar characters excluded, and invalid options. Done when: vendor/bin/phpunit passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack