Skip to main content

passpwnedcheck Package

This is a simple wrapper for Pwned Passwords API. It uses k-anonymity to securely check if your password has been leaked without actually sending your password to Pwned Passwords API.

Also, please check my blog post below for more information.

https://duongnt.com/leaked-password

Install

You can install passpwnedcheck using pip, just run the following command in the command line.

C:\> pip install passpwnedcheck

Usage

Blocking call

from passpwnedcheck.pass_checker import PassChecker

pass_checker = PassChecker()

password = 'Password'
is_leaked, count = pass_checker.is_password_compromised(password)

if is_leaked:
    print(f'Your password has been leaked {count} times')
else:
    print('Your password has not been leaked (yet)')

Alternatively, you can run pass_checker.py script from the command line, make sure to install the package via pip first.

C:\> python pass_checker.py password
Your password has been compromised xxxxxxx time(s)

Non-blocking call

from passpwnedcheck.pass_checker_async import PassCheckerAsync

# session = <Code to create an assyncio.session object>
pass_checker = PassCheckerAsync(session)

passwords = 'Password'
is_leaked, count = await pass_checker.is_password_compromised(password)

if is_leaked:
    print(f'Your password has been leaked {count} times')
else:
    print('Your password has not been leaked (yet)')

It's also possible to check multiple passwords at once. To reduce the load on Pwned Passwords API, we send requests in batches. The size of each batch is customizable, with 10 as the default.

# session = <Code to create an assyncio.session object>
pass_checker = PassCheckerAsync(session)

passwords = ['Password1', 'Password2', 'Password3', 'Password4']
results = await PassCheckerAsync.is_passwords_compromised(passwords)

print(results)

Results are stored in a dictionary, with each password as key.

{
  'Password1': xxxxxxx,
  'Password2': xxxxxxx,
  'Password3': xxxxxxx,
  'Password4': xxxxxxx
}

If you don't need to reuse the session then you can use the SessionManager helper class, which is included with this library. Just wrap the code above inside a with statement.

from passpwnedcheck.session_manager import SessionManager

async with SessionManager() as manager:
    pass_checker = PassCheckerAsync(manager.get_session())
    is_leaked, count = await pass_checker.is_password_compromised('Password')

You can also choose to increase/decrease the batch size when checking multiple passwords at once, but make sure that the number of concurrent requests is kept at a reasonable level.

passwords = ['Password1', 'Password2', 'Password3', 'Password4',...]

# Send requests to Pwned Passwords API in batch of five
results = await PassCheckerAsync.is_passwords_compromised(passwords=passwords, batch_size=5)

About k-anonymity

We utilize a mathematical property known as k-Anonymity and apply it to password hashes in the form of range queries. As such, the Pwned Passwords API service never gains enough information about a non-breached password hash to be able to breach it later.

Suppose a user enters the password test into a login form and the service they are logging into is programmed to validate whether their password is in a database of leaked password hashes. Firstly the client will generate a hash (in our example using SHA-1) of a94a8fe5ccb19ba61c4c0873d391e987982fbbd3. The client will then truncate the hash to a predetermined number of characters (for example, 5) resulting in a Hash Prefix of a94a8. This Hash Prefix is then used to query the remote database for all hashes starting with that prefix. The entire hash list is then downloaded and each downloaded hash is then compared to see if any match the locally generated hash. If so, the password is known to have been leaked.

License

MIT License

https://opensource.org/licenses/MIT

Metadata

Release files for passpwnedcheck 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for passpwnedcheck 2.0.0
File Size Uploaded
passpwnedcheck-2.0.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for passpwnedcheck 2.0.0
File Interpreter ABI Platform
passpwnedcheck-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / passpwnedcheck-2.0.0.tar.gz

Download URL passpwnedcheck-2.0.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c5efc9cff73fb4dd0d645d116a0cb47406cf9d9b02df0cf22680b9368cc3a54f
BLAKE2b-256 checksum
How to use checksums
d15c5e62a37f604f44eaf924abd42e7dfc2a0aeec860fa0d7164a997f6b0e18b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.2

Release files / passpwnedcheck-2.0.0-py3-none-any.whl

Download URL passpwnedcheck-2.0.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fed20b81112080fa07e2f2762d1e29d3fd6a0aa11a2f5591670e2591ff9a703b
BLAKE2b-256 checksum
How to use checksums
140df0b2eb4bf735305d1a888f007d3fb4d17ff577f9fecb1e4d5b004e4bcfdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.2

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page