The moschitta-auth
package provides authentication functionality for the Moschitta Framework, enabling developers to implement user authentication and authorization in their applications.
You can install moschitta-auth
via pip:
pip install moschitta-auth
Or use it with Poetry:
poetry add moschitta-auth
To use moschitta-auth
, you need to initialize an instance of the BasicAuthenticator
class with the path to the database where user information is stored.
from moschitta_auth.basic_authenticator import BasicAuthenticator
# Initialize the authenticator with the path to the database
authenticator = BasicAuthenticator(db_path='auth.db')
You can use the register_user
method of the BasicAuthenticator
class to register a new user.
# Register a new user
authenticator.register_user(username='john_doe', password='password123')
Authenticate users using the authenticate_user
method of the BasicAuthenticator
class.
# Authenticate a user
authenticated = authenticator.authenticate_user(username='john_doe', password='password123')
After authentication, you can implement access control logic based on user roles and permissions.
if authenticated:
# Allow access to restricted resources
...
else:
# Redirect to login page or deny access
...
__init__(db_path: str)
: Initializes the authenticator with the path to the database.register_user(username: str, password: str) -> None
: Registers a new user with the provided username and password.authenticate_user(username: str, password: str) -> bool
: Authenticates a user with the provided username and password.__len__() -> int
: Returns the total number of registered users in the database.
Contributions to moschitta-auth
are welcome! You can contribute by opening issues for bugs or feature requests, submitting pull requests, or helping improve the documentation.
This project is licensed under the terms of the MIT License.