Skip to main content

A lightweight, secure Python library for checking password similarity

Project description

Passim (Python)

Passim is a lightweight, secure Python library for checking password similarity during password changes or resets. It ensures users don't reuse passwords that are too similar to their previous ones, enhancing security in authentication systems. This version (v1) uses an n-gram-based approach, with a future v2 planned to leverage homomorphic encryption for improved security.

Features

  • Secure password hashing with bcrypt.
  • Similarity checking using n-gram sketches.
  • Configurable parameters (n-gram size, similarity threshold, etc.).

Installation

Install via PyPI:

pip install passim

Or install from source:

git clone https://github.com/nasredeenabdulhaleem/passim.git
cd passim
pip install .

Requirements:

  • Python 3.6+
  • bcrypt (automatically installed)

Usage

from passim import Passim

# Initialize Passim with default settings
p = Passim()

# Store an initial password
password = "Password123"
hash_, sketch = p.store_password(password)
print(f"Stored hash: {hash_[:10]}...")
print(f"Stored sketch: {sketch}")

# Check a similar password
new_password = "Password124"
is_similar = p.check_similarity(sketch, new_password)
print(f"'{new_password}' is{' ' if is_similar else ' not '}too similar")

# Attempt to change password
success, (new_hash, new_sketch) = p.change_password(hash_, sketch, "TotallyNew")
print(f"Password change: {'Accepted' if success else 'Rejected'}")

API Documentation

Configuration

Passim supports customization via constructor parameters:

  • n_gram_size (int, default: 3): Size of n-grams for similarity checking.
  • similarity_threshold (float, 0-1, default: 0.5): Proportion of matching n-grams that flags a password as "too similar."
  • num_ngrams_to_store (int, default: 5): Maximum n-grams stored in the sketch.

Example:

p = Passim(n_gram_size=4, similarity_threshold=0.7, num_ngrams_to_store=3)

Methods

store_password

Stores a password by generating a bcrypt hash and similarity sketch.

  • Input: password (str)
  • Output: Tuple (hash: bytes, sketch: Set[str])

check_similarity

Checks if a new password is too similar to an old one.

  • Input: old_sketch (Set[str]), new_password (str)
  • Output: bool (True if too similar)

change_password

Attempts to change a password, rejecting it if too similar.

  • Input: old_hash (bytes), old_sketch (Set[str]), new_password (str)
  • Output: Tuple (success: bool, (new_hash: bytes, new_sketch: Set[str]) or (None, None))

Security Notes

  • Password Hashing: Uses bcrypt with a unique salt for each password.
  • Similarity Sketch: Stores hashed n-grams, not plaintext. However, this method may leak structural info (e.g., common trigrams). A future v2 will use homomorphic encryption to eliminate this risk.
  • Storage: Store hash and sketch securely (e.g., in a database with access controls).

Roadmap

  • v2: Replace n-gram sketches with homomorphic encryption.
  • Add more similarity metrics (e.g., edit distance).
  • Expand test coverage.

Contributing

Open issues or submit pull requests at: github.com/nasredeenabdulhaleem/passim

License

MIT License © 2025 Abdulhaleem Nasredeen

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

passim-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

passim-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file passim-0.1.0.tar.gz.

File metadata

  • Download URL: passim-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for passim-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09d80e822858c8207a46d75a4935329ae5c08fb31ba817ffa9028921ae8bea1f
MD5 928b027f8042688def243cb4e24018ca
BLAKE2b-256 821f168b4895859b069c16f46af98c52dbbb4686595069b61183474542788345

See more details on using hashes here.

File details

Details for the file passim-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: passim-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for passim-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f627905bf898c652bf81b9601c85d68d5518c4e670430925de7d9524554e0185
MD5 9339a368d62eb5600f48e898a3eb30a1
BLAKE2b-256 cb59b3999e1f175b262f7d0d2b37c8d3ed2d4c363da22f820128392e3dd915b4

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