Skip to content

About

safely practice a new password until you memorize it

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

pwPractice

A small command-line tool for practicing a password, e.g. a password-manager master password or a disk-encryption passphrase you rarely type, so you don't forget it.

It stores a partial hash of your password, not the password itself and not a full hash. That's enough to catch typos while you practice. It isn't enough for someone who steals the file to confirm a guess.

How it works

  • init picks a random salt, computes scrypt(password, salt), and keeps only the first 16 bits of the result.
  • practice computes the same 16 bits from what you type and compares them.

A full hash (or an encrypted known message) would be a perfect oracle. Anyone with the file could guess offline until it said "yes", and the file would confirm the right answer. With 16 bits, roughly 1 in 65,536 wrong passwords also match. Brute-forcing the file doesn't produce your password. It produces a huge pile of equally plausible candidates, and the real one is just one of them.

The cost is that a typo has the same 1-in-65,536 chance of being accepted as correct. For practice, that's a fine trade.

Requirements

Python 3.9 or newer. Nothing to install: it uses only the standard library.

Usage

git clone https://github.com/ancientastronauttheorist/pwPractice.git
cd pwPractice

python3 pwPractice.py init vault.json       # prompts for the password twice
python3 pwPractice.py practice vault.json   # practice as often as you like
$ python3 pwPractice.py practice vault.json
Password practice. Type your password; press Enter on an empty line to quit.
>
✅ Correct! (streak: 1)
>
❌ Incorrect.
>
✅ Correct! (streak: 1)
>
✅ Correct! (streak: 2)
>
3/4 correct, best streak 2.
Bye.

Each attempt takes a fraction of a second. That's scrypt doing its job.

Options

Option Meaning
init --bits N Bits of the hash to keep, 8–32 (default 16). More bits catch more typos but tell an attacker more. 16 is a good balance. Above ~24, the file starts to work as a real verifier again.
init --force Replace an existing token file. Without it, init refuses to overwrite.

What the token file does and doesn't protect

It protects against someone who gets the file learning a strong password from it. Guessing offline only narrows the candidates down by a factor of 2^bits. An attacker with a list of 2^40 guesses is left with about 2^24 that all match.

It doesn't protect:

  • Weak passwords. If your password is among the first few thousand guesses an attacker would try, a 16-bit check narrows things to a handful of candidates, and they can try those against the real service. If the password is weak enough for that to matter, change it.
  • Your password while you type it. A keylogger or someone watching you sees it like anywhere else.
  • Memory. Python can't reliably erase strings from memory, so this tool doesn't pretend to. The one thing it does do is disable core dumps (on Linux/macOS), so a crash can't write your password to disk.

Still, treat the file as mildly sensitive. init creates it readable only by you (0600). There's no reason to share it.

File format

{
  "format": "pwpractice-v2",
  "kdf": "scrypt",
  "params": { "n": 131072, "r": 8, "p": 1 },
  "salt": "<16 random bytes, base64>",
  "check_bits": 16,
  "check": "<first 16 bits of scrypt(password), base64>"
}

The scrypt cost (n = 2^17, r = 8, p = 1, about 128 MiB) is OWASP's recommended minimum. When reading a file, the tool rejects parameters outside sane bounds, so a corrupt or tampered file can't make it use gigabytes of memory or a trivially cheap hash.

Passwords are Unicode-normalized (NFC) before hashing, so the same password typed on a different OS or keyboard layout still matches.

Upgrading from v1 tokens

Old pwpractice-v1 files stored AES-GCM encryption of a known message, which is a complete password verifier. Anyone with the file can brute-force it offline and confirm the password. The tool refuses to read them. Delete every copy of any v1 token file, including backups and synced folders, and run init again. If a v1 file ever left your machine and the password it protected isn't very strong, consider changing that password.

Running the tests

python3 -m unittest discover -s tests

License

The Unlicense. See LICENSE.

About

safely practice a new password until you memorize it

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages