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.3.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.3-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: allsafe_auth-1.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 b334fc3af25f69d53decf10ccf99f66406187554e7272a39028e24e1763ccc73
MD5 057b2fb0d8497f548845123026d0bc26
BLAKE2b-256 849dba2326412de9bbcc5c4b88ab05733f4fc240d362d764c41ae0f47b0515a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: allsafe_auth-1.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3cd7a00a1cf6965cb2c03752c386c0b22d1b01e6b7c1a35d5ce6382837de1d03
MD5 c71f8604659eddfdbd65fc244ef407e3
BLAKE2b-256 d82633c7c08369bbb2549f19546a6008fda8ae040a06d9de51f5214ed023a722

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