Skip to main content

A robust and flexible license key management system for Python applications, enabling secure license validation, renewal, and revocation with ease.

Project description

AuthKeyManager

AuthKeyManager is a class used to manage license keys, supporting both MySQL and MongoDB databases. With this class, you can generate, store, query, validate, and delete license keys for specific users.

Features

  • Database Support: MySQL and MongoDB
  • License Key Generation: Generates random 12-character license keys in a custom format.
  • Record Creation: Stores license keys associated with user IDs in the database.
  • Query: Retrieves all license keys for a given user.
  • Validation: Verifies if a license key is valid for a specific user.
  • Deletion: Removes a specific license key for a user from the database.

Installation

pip install auth_key_manager

Usage

1. Initializing the Class

from auth_key_manager import AuthKeyManager

# Initialize with MySQL
auth_manager = AuthKeyManager(
    db_type="mysql",
    connection_params={
        "host": "localhost", # Hostname
        # "port": 3306,  # Optional: Default MySQL port is 3306
        "user": "",
        "password": ""
    },
    db_name="", # Database name
    table_name="", # Table name 
    column_user_id="", # Column name for user ID
    column_license_key="", # Column name for license key
    column_created_at=""  # Column name for creation date
)

# Initialize with MongoDB
auth_manager = AuthKeyManager(
    db_type="mongodb",
    connection_params={
        "host": "localhost", # Hostname and 
        "port": 27017 # Optional: Default MongoDB port is 27017
        },
    db_name="", # Database name
    table_name="",  # Collection name 
    column_user_id="", # Field name for user ID
    column_license_key="", # Field name for license key
    column_created_at="" # Field name for creation date
)

2. Generating a License Key

# Generate a license key for a user
user_id = "user123"
license_key = auth_manager.create_license_record(user_id)
print(f"Generated License Key: {license_key}")
# Output: Generated License Key: LICENSE-XXXX-XXXX-XXXX

3. Querying License Keys for a User

# Query all license keys for a user
user_id = "user123"
license_keys = auth_manager.query_license_keys(user_id)
# Output: ['LICENSE-XXXX-XXXX-XXXX', 'LICENSE-XXXX-XXXX-XXXX', ...]

4. Validating a License Key

# Validate a license key for a user
user_id = "user123"
license_key = "LICENSE-XXXX-XXXX-XXXX"
is_valid = auth_manager.validate_license_key(user_id, license_key)
print(f"Is Valid: {is_valid}")
# Output: Is Valid: True or False

5. Deleting a License Key

# Delete a license key for a user
user_id = "user123"
license_key = "LICENSE-XXXX-XXXX-XXXX"
auth_manager.delete_license_key(user_id, license_key)
# Output: License key deleted successfully

6. Closing the Connection

# Close the connection
auth_manager.close_connection()

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

auth_key_manager-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

auth_key_manager-0.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file auth_key_manager-0.0.1.tar.gz.

File metadata

  • Download URL: auth_key_manager-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for auth_key_manager-0.0.1.tar.gz
Algorithm Hash digest
SHA256 34905633e03251981f3c882c28f47c92fdef2c530eeefc78a7d3be7273fe36d4
MD5 ccdc56b9485f7d3fb691b16e08f31543
BLAKE2b-256 d4369d6e1244d01cd4d8a9eedc5bee91c6b57025c8ed8e2d9cab9d88229bb454

See more details on using hashes here.

File details

Details for the file auth_key_manager-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for auth_key_manager-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d16e7159aaa27cf323071a3b267d3410f71dbd2b5ea997ffaf4358cc85fdd32
MD5 ba7435588d3db55a824f0b8cd223da2e
BLAKE2b-256 d335e5300d71fd7526fcd0e50706661e3c4d922fe01c14d21e8813d756299219

See more details on using hashes here.

Supported by

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