A python implementation of PwdHash 1 and 2
Project description
PwdHash 1 and 2, in Python
This is a Python implementation of PwdHash and PwdHash2, accessible from the command line.
It is function-equivalent to the original PwdHash browser add-on, as well as the updated version.
Installation
pip install pwdhash
Usage
Once installed with pip, pwdhash
command should be available in the PATH.
If sources are available, the script can also be called with python pwdhash.py
or ./pwdhash.py
.
❯ pwdhash -h
usage: pwdhash [-h] [-v {1,2}] [-s] [-c] [--salt SALT] [--iterations ITERATIONS] [-n] domain
Computes PwdHash1 or PwdHash2.
positional arguments:
domain the domain or uri of the site
optional arguments:
-h, --help show this help message and exit
-v {1,2}, --version {1,2}
Use PwdHash 1 or 2. Default is 1
-s, --stdin Get password from stdin instead of prompt. Default is prompt
-c, --copy Copy hash to clipboard instead of displaying it. Default is display
--salt SALT Salt (for PwdHash 2)
--iterations ITERATIONS
How many iterations (for PwdHash 2)
-n Do not print the trailing newline
PwdHash Examples
Standard PwdHash is calculated by default. Domain name is required as an argument, and password is entered in a prompt, without being displayed :
❯ pwdhash example.com
Password:
4kydhtBD9M
--stdin
It's possible to get the password from standard input. It displays the password if entered by the user:
❯ pwdhash --stdin example.com
p4ssw0rd
4kydhtBD9M
but it allows to get the password from a pipe or a file:
❯ pwdhash --stdin example.com < password
4kydhtBD9M
❯ cat password | pwdhash --stdin example.com
4kydhtBD9M
❯ echo "p4ssw0rd" | pwdhash --stdin example.com
4kydhtBD9M
--copy
It's possible to copy the password directly to the clipboard. It requires the pyperclip
module. The password isn't displayed at all.
❯ pwdhash --stdin --copy example.com < password
-n
Passwords can also be displayed without trailing newline:
❯ pwdhash --stdin example.com -n < password
4kydhtBD9M%
PwdHash2 Examples
❯ pwdhash -v2 example.com
Exception: Please define 'PWDHASH2_SALT' environment variable, or specify --salt.
PwdHash2 requires a Salt:
❯ pwdhash -v2 example.com --salt ChangeMe
Exception: Please define 'PWDHASH2_ITERATIONS' environment variable, or specify --iterations.
and a number of iterations:
❯ pwdhash -v2 example.com --salt ChangeMe --iterations 50000
Password:
7qErBOIB6R
❯ pwdhash -v2 example.com --salt ChangeMe --iterations 50000 --stdin < password
7qErBOIB6R
Environment variables
Salt and Iterations can also be specified as environment variables:
❯ PWDHASH2_SALT=ChangeMe PWDHASH2_ITERATIONS=50000 pwdhash -v2 example.com --stdin < password
7qErBOIB6R
If you define those variables inside your .bashrc
or .zshrc
, you don't need to specify them anymore:
❯ pwdhash -v2 example.com --stdin < password
7qErBOIB6R
Call from Python script
import pwdhash
print(pwdhash.extract_domain('https://subdomain.example.com/folder'))
# example.com
print(pwdhash.pwdhash('example.com', 'p4ssw0rd'))
# 4kydhtBD9M
print(pwdhash.pwdhash2('example.com', 'p4ssw0rd', 50_000, 'ChangeMe'))
# 7qErBOIB6R
Tests
❯ pytest -v
================================= test session starts ==================================
collected 9 items
test_pwdhash.py::TestPwdHash::test_empty_pwdhash PASSED [ 11%]
test_pwdhash.py::TestPwdHash::test_pwdhash1_with_domains PASSED [ 22%]
test_pwdhash.py::TestPwdHash::test_pwdhash1_with_urls PASSED [ 33%]
test_pwdhash.py::TestPwdHash2::test_pwdhash2_collisions PASSED [ 44%]
test_pwdhash.py::TestPwdHash2::test_pwdhash2_edge_cases PASSED [ 55%]
test_pwdhash.py::TestPwdHash2::test_pwdhash2_with_urls PASSED [ 66%]
test_pwdhash.py::TestPwdHashCLI::test_cli_pwdhash PASSED [ 77%]
test_pwdhash.py::TestPwdHashCLI::test_cli_pwdhash2 PASSED [ 88%]
test_pwdhash.py::TestPwdHashCLI::test_cli_pwdhash_to_clipboard PASSED [100%]
================================== 9 passed in 0.46s ===================================
Authors
- Based on Stanford PwdHash
- Joost Rijneveld, 2015
- Eric Duminil, 2022
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pwdhash-0.0.1.tar.gz
.
File metadata
- Download URL: pwdhash-0.0.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 386f21a4fc74a36cd98551f8158e78d1251c2435be0a654b9a1ed8950c456112 |
|
MD5 | 2d75e749ca26137a3eb887b9fb5113ed |
|
BLAKE2b-256 | 9ca3c54c9333e507aa2545e490315c85be791afbab3aea290267308e9164690b |
File details
Details for the file pwdhash-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pwdhash-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fc22e4147f5a0e5349eb90269a2c8c6dae0414532dcff9359f8323f1cf6f885 |
|
MD5 | 22abdc35c38a55b7972e2152db7cabaf |
|
BLAKE2b-256 | 1b09eae57e77f9b28b3ed1b30f643661b11d714ef9bfde1949045b67a226a0b3 |