Paul's Python CoursePPC

Project 1 of 20, for Caitlin

Password Generator

Passwords and passphrases for the Studio's Friday-night game server: sensible defaults, options by name, and nothing anyone can guess.

About an hour and a half, in 21 steps.

Sign up free to open itLog in

Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • CaitlinWe're getting a game server in the Studio for Friday nights, and everyone in the class is going to need a password.
  • CaitlinI made six up myself and Yahya guessed four of them before the kettle had even boiled.
  • CaitlinThe other two were highscore1 and highscore2, which he got straight after.
  • PaulLet's get a program to make them instead, with sensible defaults and a few options for anyone who's fussy.

Write passwords.py, with a docstring in every function.

  1. make_password(length=12, digits=True, symbols=False, avoid_lookalikes=True) returns a password of length characters. It always uses lower case and capital letters; digits if digits is true; and the characters in SYMBOLS if symbols is true. It has at least one character of every kind it uses. With avoid_lookalikes, it never uses any of LOOKALIKES (Il1O0o).
  2. make_passphrase(words=4, sep="-", capitalise=False) returns that many words from the word list, joined by sep. With capitalise, each word starts with a capital.
  3. make_passwords(*names, issued=None, **options) makes a password for each name with make_password(**options) and returns a dictionary of name to password. Given an issued dictionary, it adds to that one and returns it; without one, it starts a new dictionary every time.

Anything a password is made from comes from secrets, never random.

What it prints
Passwords for the game server:
  Aaesha: tK7fWq2mRbXe
  Caitlin: Hn3zVp8sCwYd
  Yahya: qD4hTx9jMkPa
Passphrase for the Wi-Fi: ample-crust-vowel-tidal

What you learn

What's in it

  1. Characters nobody can guess
  2. Characters to choose from
  3. A value to fall back on
  4. Something to fall back on
  5. Arguments by name
  6. By name
  7. Saying what it does
  8. Which string
  9. Any number of names
  10. The size goes where
  11. Any number of options
  12. Any number of classmates
  13. A default made once
  14. The default that remembers
  15. The same numbers every run
  16. The same every time
  17. How Paul would do it
  18. Fix Yahya's version
  19. Make the password generator
  20. Ship it