Skip to main content

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="mydb",
    mail_info={
        mail_server="smtp.example.com",
        mail_port=587,
        mail_username="your_email@example.com",
        mail_password="your_email_password"
    }, # Optional: Include if using email verification
    blocking=True/False  # Optional: True to enable user blocking
)

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.example_func(args)

All functions return a dictionary: {"success": True/False, "message": "specific message"}.

User Registration & Verification

  • register_user(email, password, custom_data=False)

    • Registers a user and sends a verification code via email. custom_data can be any additional user info.
  • register_user_no_verif(email, password, custom_data=False)

    • Registers a user without email verification. custom_data is optional.
  • verify_user(email, code)

    • Verifies a user by checking the provided verification code.

Authentication

  • authenticate_user(email, password)
    • Authenticates a user. Requires the user to be verified.

Password Management

  • reset_password_no_verif(email, old_password, new_password)

    • Resets the user's password after verifying the old password. No email code required.
  • 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.

User Deletion & Blocking

  • delete_user(email, password, del_from_blocking=True)

    • Deletes a user from the database if credentials match. If del_from_blocking is True, also removes from the blocking database.
  • block_user(email)

    • Blocks a user by setting their status to "blocked".
  • unblock_user(email)

    • Unblocks a user.

Custom User Data

  • get_cust_usr_data(email)

    • Retrieves all custom user data for the user.
  • get_some_cust_usr_data(email, field)

    • Retrieves a specific field from the user's custom data.
  • replace_usr_data(email, custom_data)

    • Replaces the user's custom data with new data.
  • update_usr_data(email, field, custom_data)

    • Updates a specific field in the user's custom data.

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


Download files

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

Source Distribution

easy_mongodb_auth_handler-1.0.5.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

easy_mongodb_auth_handler-1.0.5-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file easy_mongodb_auth_handler-1.0.5.tar.gz.

File metadata

File hashes

Hashes for easy_mongodb_auth_handler-1.0.5.tar.gz
Algorithm Hash digest
SHA256 26edd5cadb1f0a6b7b2171dc471b1698d38fe7ef26bdbc84705ef3bdb93d57dc
MD5 8df6f50b7d4532823fb93db59b16367f
BLAKE2b-256 090c268ff4dd0f5bd0a2735a42ee56afe461df23bed0f14055b8af452e23f502

See more details on using hashes here.

Provenance

The following attestation bundles were made for easy_mongodb_auth_handler-1.0.5.tar.gz:

Publisher: python-publish.yml on lukbrew25/easy_mongodb_auth_handler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easy_mongodb_auth_handler-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_mongodb_auth_handler-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6964c7161cd6ee4fed07523f08f41739c3090a3ea0d311e76607cb96759af0cf
MD5 11270fd5160e082151d62e9f9d530abc
BLAKE2b-256 1368ff0be2a2d8a392e74456cfa4bb910de9d6b75ce715ad737ca8bee00dbd44

See more details on using hashes here.

Provenance

The following attestation bundles were made for easy_mongodb_auth_handler-1.0.5-py3-none-any.whl:

Publisher: python-publish.yml on lukbrew25/easy_mongodb_auth_handler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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