CLI Password Generator with Strength Rules
Build a Go command-line tool that creates strong random passwords. You choose the length and which kinds of characters to include (lowercase, uppercase, digits and symbols), it guarantees at least one of each chosen kind, and it tells you how strong each password is, measured as entropy in bits and described as weak, fair, strong or very strong. It can create many passwords at once, or a memorable passphrase made of random words. Randomness comes from crypto/rand, the source meant for security, never from math/rand. It's a good first Go project: you'll learn the flag package, secure randomness, working with strings and runes, simple math for strength, and table-driven tests.
- Estimate
- ~6h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
crypto/rand · flag package
Project roadmap
- 01
Define the options
~1hRun go mod init and use the flag package to define -length (default 16), -lower, -upper, -digits and -symbols (all on by default), -count (default 1), and -exclude-similar (leave out characters that look alike, such as l, 1, O and 0). Validate: length between 8 and 128, and at least one character kind chosen. Done when: invalid options print a clear message and the usage.
- 02
Generate secure passwords
~1.5hBuild the character set from the chosen kinds, and pick each character with crypto/rand.Int so every character is equally likely (never use modulo on random bytes, which makes some characters more likely). Guarantee at least one character of each chosen kind by placing one of each, filling the rest, then shuffling with a secure Fisher-Yates shuffle. Done when: generated passwords have the right length and always contain each chosen kind.
- 03
Estimate strength
~1hWrite a function that computes entropy as length × log2(number of possible characters), and a function that turns bits into a label (for example under 50 weak, 50 to 80 fair, 80 to 100 strong, and above that very strong). Print each password with its bits and label. Explain in README.md why this estimate only holds for truly random passwords. Done when: a 16-character password from all four kinds shows about 105 bits.
- 04
Add batch mode and passphrases
~1hWith -count, print several passwords, one per line. Add -words N to create a passphrase of N random words (from a word list file embedded with go:embed, such as the EFF long word list) joined by dashes, with its entropy (N × log2 of the list size). Done when: -count 5 prints 5 passwords, and -words 5 prints a passphrase with its strength.
- 05
Write tests
~1.5hWrite table-driven tests: lengths and option validation, every chosen kind present, excluded characters never appearing, entropy values for known inputs, and labels at their boundaries. Add a statistical check over many passwords that every character appears with roughly equal frequency. Done when: go test ./... passes.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack