Skip to main content

A complete authentication library including TOTP, HOTP, Active Directory, and more.

Project description

AllSafe Authentication Library

GitHub GitHub Stars GitHub Issues

GitHub Repository: AllSafe Authentication

AllSafe Authentication is a comprehensive Python library designed to simplify and enhance user authentication and authorization in your applications. It supports a wide range of authentication methods, MFA, user/role management, and robust security features. Built to be modular and extensible, AllSafe can be tailored to your unique security needs.


🔧 Features

🔐 Authentication Methods

  • Active Directory (LDAP)
  • TOTP (Time-based One-Time Password)
  • HOTP (HMAC-based One-Time Password)
  • Google Authenticator integration
  • OAuth2 & OpenID Connect
  • SAML-based Single Sign-On (SSO)

🔑 Multi-Factor Authentication (MFA)

  • Enforce MFA
  • Backup via SMS or email

👥 User & Role Management

  • User registration, login, update, deletion
  • Role-Based Access Control (RBAC)
  • Pluggable resolvers: LDAP, MySQL, PostgreSQL, MongoDB

🛡️ Security

  • Password policies
  • Session management
  • Encryption utilities
  • Audit logging

🧰 Utilities

  • QR Code generation
  • Configuration loader
  • Input validators

📦 Installation

pip install allsafe_auth

🚀 Usage Examples

✅ TOTP Setup & Verification

from allsafe_auth.authentication.totp import TOTP
from allsafe_auth.utils.qr_code_generator import QRCodeGenerator

# Generate secret and QR Code URI
secret = TOTP.generate_secret()
totp = TOTP(secret)
uri = QRCodeGenerator.generate_uri("AllSafeApp", "user@example.com", secret)
print(f"TOTP URI: {uri}")

# Verify code from user
user_code = input("Enter TOTP code from your app: ")
if totp.verify(user_code):
    print("✅ TOTP verification successful.")
else:
    print("❌ TOTP verification failed.")

🔁 HOTP Generation, QR, and Verification

from allsafe_auth.authentication.hotp import HOTP
from allsafe_auth.utils.qr_code_generator import QRCodeGenerator

# Generate HOTP and QR
secret_key = "JBSWY3DPEHPK3PXP"
counter = 1
hotp = HOTP(secret_key)
code = hotp.generate(counter=counter)
print(f"Generated HOTP (counter={counter}): {code}")

# QR Code URI
uri = QRCodeGenerator.generate_uri("AllSafeApp", "user@example.com", secret_key, type='hotp', counter=counter)
QRCodeGenerator.save_to_file(uri, "hotp_qr_code.png")
print("QR code saved to hotp_qr_code.png")

# Verify user input
user_code = input("Enter the HOTP code: ")
if hotp.verify(user_code, counter=counter):
    print("✅ HOTP verification successful.")
else:
    print("❌ HOTP verification failed.")

⚠️ Always increment and persist the HOTP counter securely after each verification.


🔒 Password Policy Validation

from allsafe_auth.security.password_manager import PasswordManager, PasswordPolicy

pm_none = PasswordManager(policy=PasswordPolicy.no_restriction())
pm_medium = PasswordManager(policy=PasswordPolicy.medium())
pm_strong = PasswordManager(policy=PasswordPolicy.strong())

print(pm_none.validate_password_strength("123"))               # ✅ True
print(pm_medium.validate_password_strength("abc123"))          # ❌ False
print(pm_medium.validate_password_strength("abc12345"))        # ✅ True
print(pm_strong.validate_password_strength("Abc123!@#def"))    # ✅ True
print(pm_strong.validate_password_strength("123456789012"))    # ❌ False

📁 Module Export Declaration

In your __init__.py, export key metadata like so:

__all__ = [
    "__version__",
    "__author__",
    "__license__",
    "__copyright__",
    "__github_link__",
    "__readme__"
]

🙌 Contributing

We welcome contributions! Please check the issues and submit a pull request.


📜 License

This project is licensed under the terms of the MIT License.

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

allsafe_auth-1.1.2.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

allsafe_auth-1.1.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file allsafe_auth-1.1.2.tar.gz.

File metadata

  • Download URL: allsafe_auth-1.1.2.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for allsafe_auth-1.1.2.tar.gz
Algorithm Hash digest
SHA256 5e89b7a610232c113f395b1173761fe2d4a8e35f38ce4c585d479ded0336a225
MD5 517da7c6dd57b59f640721b4c1e5cb88
BLAKE2b-256 22aa968957c38ebf030f0853547b6db0231da08bf4733a34d07aa49652e6815f

See more details on using hashes here.

File details

Details for the file allsafe_auth-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: allsafe_auth-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for allsafe_auth-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 902f50ad259661729f9e36ca82f412276437c94416920d05975655b37d086453
MD5 41e85cca30c024ca383c71c05ef5be68
BLAKE2b-256 502ab8c698d8bc7685add40c1285367cd32c301a70a3cd531480e878d01da578

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