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.
Metadata
Release files for auth-key-manager 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| auth_key_manager-0.0.1.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| auth_key_manager-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / auth_key_manager-0.0.1.tar.gz
| Download URL | auth_key_manager-0.0.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34905633e03251981f3c882c28f47c92fdef2c530eeefc78a7d3be7273fe36d4
|
|
BLAKE2b-256 checksum How to use checksums |
d4369d6e1244d01cd4d8a9eedc5bee91c6b57025c8ed8e2d9cab9d88229bb454
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / auth_key_manager-0.0.1-py3-none-any.whl
| Download URL | auth_key_manager-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d16e7159aaa27cf323071a3b267d3410f71dbd2b5ea997ffaf4358cc85fdd32
|
|
BLAKE2b-256 checksum How to use checksums |
d335e5300d71fd7526fcd0e50706661e3c4d922fe01c14d21e8813d756299219
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for auth-key-manager 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.