A small command-line password generator written in Python. It uses the standard library's secrets module, so every character comes from the operating system's cryptographically secure random source (not random). One file, no dependencies.
Find a file
joshdevelopsIRL fe368cf93c docs: add README with usage, options and examples
Includes the MIT license.
2026-10-12 12:36:39 -05:00
.gitignore chore: add .gitignore for python cache files 2026-10-12 12:35:36 -05:00
createpass.py fix: make --hex real hex, guarantee char types, validate input 2026-10-12 12:35:54 -05:00
LICENSE docs: add README with usage, options and examples 2026-10-12 12:36:39 -05:00
README.md docs: add README with usage, options and examples 2026-10-12 12:36:39 -05:00

createpass

A small command-line password generator written in Python. It uses the standard library's secrets module, so every character comes from the operating system's cryptographically secure random source (not random). One file, no dependencies.

Features

  • Cryptographically secure randomness via secrets
  • Configurable password length
  • Generate one password or a whole batch
  • Exclude characters you do not want (look-alikes, or ones a site rejects)
  • Hex-only mode (0-9, a-f)
  • Each password contains at least one uppercase letter, lowercase letter, digit, and symbol by default
  • Print to the console or write to a file, one password per line
  • Clear error messages for invalid input

Requirements

Python 3.10 or newer.

Usage

python3 createpass.py [-l LENGTH] [-a AMOUNT] [-f FILE] [-e EXCLUDE] [--hex] [--no-require-all]
Option Description Default
-l, --length Length of each password 12
-a, --amount Number of passwords to generate 1
-f, --file Write passwords to this file instead of printing prints to console
-e, --exclude Characters to leave out of generation none
--hex Generate hex-only passwords (0-9, a-f) off
--no-require-all Do not force one character from each group off

The default character set is uppercase letters, lowercase letters, digits, and these symbols: ! @ # $ % ^ & * + ? . = - _ " '

Examples

# One 12-character password
python3 createpass.py

# Three 16-character passwords
python3 createpass.py -a 3 -l 16

# Skip look-alike characters
python3 createpass.py -a 2 -e "O0Il1"

# 20-character hex string (handy for tokens and keys)
python3 createpass.py --hex -l 20

# 100 passwords saved to a file
python3 createpass.py -a 100 -l 20 -f passwords.txt

Sample output (yours will differ, since it is random):

$ python3 createpass.py -a 3 -l 16
f%Wu"C7v0HiUf3&=
f4$^9XdY1GG1@$Ne
pHmLMgslkK1nhc*a

$ python3 createpass.py --hex -l 20
76a6ce6ad002125e1eb5

How it works

  1. build_pools assembles the character groups (upper, lower, digits, symbols, or just hex digits) and removes anything passed to --exclude.
  2. generate_password picks one character from each group so every type is represented, fills the remaining length from the combined pool with secrets.choice, then shuffles with secrets.SystemRandom so the guaranteed characters do not sit in predictable positions.
  3. main validates the input, generates the requested number of passwords, and prints them or writes them to a file.

If the length is shorter than the number of groups, or you pass --no-require-all, every character is simply drawn uniformly from the full pool.

Install as a command (optional)

chmod +x createpass.py
sudo cp createpass.py /usr/local/bin/createpass
createpass -l 20

License

MIT. See LICENSE.