A user authentication and verification system using MongoDB.
Project description
easy_mongodb_auth_handler
A user authentication and verification system using MongoDB, supporting email-based verification, password hashing, and reset mechanisms.
Installation
pip install easy-mongodb-auth-handler
Setup
Make sure you have MongoDB installed and running. You also need access to an SMTP mail server for sending verification and reset codes.
Project Structure
easy_mongodb_auth_handler/
├── setup.py
├── src/
│ └── easy_mongodb_auth_handler/
│ ├── __init__.py
│ ├── auth.py
│ └── utils.py
Features
- User registration with and without email verification
- Email format validation
- Secure password hashing with bcrypt
- User login/authentication
- Password reset via email verification
- MongoDB-based user data persistence
Usage
from easy_mongodb_auth_handler import Auth
auth = Auth(
mongo_uri="mongodb://localhost:27017",
db_name="myapp",
mail_server="smtp.example.com",
mail_port=587,
mail_username="your_email@example.com",
mail_password="your_email_password"
)
This code initializes the package. The mail arguments are not required, but needed to use verification code functionality. All methods return True or False with additional detailed outcome reports.
Function Reference - auth.func_name(params)
All following functions return a dictionary with the following values: {"success": True/False Boolean, "message": "specific error or success message string"}.
register_user(email, password, blocking=True)
Registers a user and sends a verification code via email. Returns a success status and message. Blocking is an optional parameter that is set to True by default. When blocking is set to True, the user will not be allowed to register if they are blocked.
verify_user(email, code, blocking=True)
Verifies a user by checking the provided verification code against the database entry. Blocking is an optional parameter that is set to True by default. When blocking is set to True, the user will not be allowed to verify if they are blocked.
authenticate_user(email, password, blocking=True)
Authenticates a user by checking their email and password. Requires the user to be verified. Blocking is an optional parameter that is set to True by default. When blocking is set to True, the user will not be allowed to authenticate if they are blocked.
delete_user(email, password, del_from_blocking=True)
Deletes a user from the database if credentials match. del_from_blocking is a boolean that determines if the user should be removed from the blocking database if they are currently blocked. If set to true, the entry will be deleted and the user will no longer be blocked. It is optional but set to True by default.
register_user_no_verif(email, password, blocking=True)
Registers a user without requiring email verification. Useful for internal tools or test environments. Blocking is an optional parameter that is set to True by default. When blocking is set to True, the user will not be allowed to register if they are blocked.
reset_password_no_verif(email, old_password, new_password)
Resets the user's password after verifying the old password. Does not require an email code.
generate_reset_code(email)
Generates and emails a password reset code to the user.
verify_reset_code_and_reset_password(email, reset_code, new_password)
Verifies a password reset code and resets the user's password.
block_user(email)
Blocks a user by setting their status to "blocked" in the database. This prevents login attempts and most functions.
Requirements
- Python >= 3.8
- pymongo >= 4.0.0
- bcrypt >= 4.0.0
License
GNU Affero General Public License v3
Author
Lukbrew25
...and all future contributors!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_mongodb_auth_handler-1.0.4.tar.gz.
File metadata
- Download URL: easy_mongodb_auth_handler-1.0.4.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d53044b41114946603fb09f619cde537ff1173145c0fefb92f3899f9b773a0b
|
|
| MD5 |
922f17c9f3a827ecbebdb865edadfc61
|
|
| BLAKE2b-256 |
4d4b9765652c2f36ce32d832d4881a91cdcab8cf82f8134fba08662827cf2184
|
Provenance
The following attestation bundles were made for easy_mongodb_auth_handler-1.0.4.tar.gz:
Publisher:
python-publish.yml on lukbrew25/easy_mongodb_auth_handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easy_mongodb_auth_handler-1.0.4.tar.gz -
Subject digest:
4d53044b41114946603fb09f619cde537ff1173145c0fefb92f3899f9b773a0b - Sigstore transparency entry: 212174715
- Sigstore integration time:
-
Permalink:
lukbrew25/easy_mongodb_auth_handler@f1631704d80556e9b43ca02e7987fa2ec65b1304 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/lukbrew25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f1631704d80556e9b43ca02e7987fa2ec65b1304 -
Trigger Event:
release
-
Statement type:
File details
Details for the file easy_mongodb_auth_handler-1.0.4-py3-none-any.whl.
File metadata
- Download URL: easy_mongodb_auth_handler-1.0.4-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d58230726962fae9b6f5eac166f1b5e27d26e0be81788120db7e7df7f64fde0
|
|
| MD5 |
f565e1eac4decd7bbae0abd4b75e0242
|
|
| BLAKE2b-256 |
8e44e22348bf8b60d40caf491f6f0e7bc4e5f303b4d8f9bf7e902e44745cbe1b
|
Provenance
The following attestation bundles were made for easy_mongodb_auth_handler-1.0.4-py3-none-any.whl:
Publisher:
python-publish.yml on lukbrew25/easy_mongodb_auth_handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easy_mongodb_auth_handler-1.0.4-py3-none-any.whl -
Subject digest:
4d58230726962fae9b6f5eac166f1b5e27d26e0be81788120db7e7df7f64fde0 - Sigstore transparency entry: 212174718
- Sigstore integration time:
-
Permalink:
lukbrew25/easy_mongodb_auth_handler@f1631704d80556e9b43ca02e7987fa2ec65b1304 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/lukbrew25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f1631704d80556e9b43ca02e7987fa2ec65b1304 -
Trigger Event:
release
-
Statement type: