Skip to main content

Test for pwned password

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

passpwnedcheck-2.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

passpwnedcheck-2.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file passpwnedcheck-2.0.0.tar.gz.

File metadata

  • Download URL: passpwnedcheck-2.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for passpwnedcheck-2.0.0.tar.gz
Algorithm Hash digest
SHA256 c5efc9cff73fb4dd0d645d116a0cb47406cf9d9b02df0cf22680b9368cc3a54f
MD5 d6737b8d009d908774fb1fa3ff0640dc
BLAKE2b-256 d15c5e62a37f604f44eaf924abd42e7dfc2a0aeec860fa0d7164a997f6b0e18b

See more details on using hashes here.

File details

Details for the file passpwnedcheck-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: passpwnedcheck-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for passpwnedcheck-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fed20b81112080fa07e2f2762d1e29d3fd6a0aa11a2f5591670e2591ff9a703b
MD5 579cacdd7aad5cf9a0e65c2647aa95bf
BLAKE2b-256 140df0b2eb4bf735305d1a888f007d3fb4d17ff577f9fecb1e4d5b004e4bcfdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page