Overview
The authentication module provides secure user registration and authentication using bcrypt for password hashing. All functions are async and return user dictionaries orNone on failure.
Register User
Parameters
Full name of the user. Will be stripped of leading/trailing whitespace.
Email address. Converted to lowercase and stripped. Must be unique.
Student identifier used for barcode scanner login. Stripped and must be unique.
Plain text password. Will be hashed using bcrypt with auto-generated salt.
Returns
Returns user object on success,
None if email or student_id already existsSecurity Notes
- Passwords are hashed using bcrypt with auto-generated salts
- Email addresses are case-insensitive (stored as lowercase)
- Password hashes are never returned in user objects
- Duplicate emails or student IDs result in
Nonereturn value
Authenticate User
Parameters
Email address to authenticate. Converted to lowercase and stripped.
Plain text password to verify against stored hash.
Returns
Returns user object on successful authentication,
None if credentials are invalidImplementation Details
The function:- Looks up user by email (case-insensitive)
- Returns
Noneif user not found - Verifies password using
bcrypt.checkpw() - Returns user dict (without password_hash) if password matches
- Returns
Noneif password doesn’t match
Get User by ID
Parameters
Student ID to lookup. Converted to string and stripped. Typically scanned from barcode.
Returns
Returns user object if found,
None if student ID doesn’t existUse Cases
- Barcode Scanner Login: Primary authentication method at kiosk terminals
- Quick Lookup: Fast user identification without password
- Card-Based Access: Simplified login flow for physical kiosks
Security Considerations
- No password required - suitable only for physical kiosk environments
- Check
activestatus before granting access - Student IDs should be treated as semi-public identifiers
- Consider additional authentication for sensitive operations