A modular Python project that validates username and password input based on predefined rules, using custom exceptions, object-oriented design, and regular expressions. This project is structured for clarity, scalability, and professional-level maintainability.
- Modular architecture with clear file separation
- Strong validation logic for both username and password
- Custom exception hierarchy with detailed messages
- Continuous user input until valid credentials
- Designed for extensibility (future GUI, database, API integration)
login_validator/
βββ main.py # Entry point, handles user interaction
βββ validator.py # Contains check_input() logic
βββ exceptions/
β βββ __init__.py # Marks the folder as a package
β βββ username_exceptions.py # Custom exceptions for username errors
β βββ password_exceptions.py # Custom exceptions for password errors
+------------------+
| main.py |
|------------------|
| input() |
| try/except |
| print(errors) |
+--------+---------+
|
v
+--------+---------+
| validator.py |
|------------------|
| check_input() |
| - validate user |
| - raise custom |
+--------+---------+
|
+------------------+------------------+
| |
v v
+---------------------------+ +----------------------------+
| username_exceptions.py | | password_exceptions.py |
|---------------------------| |----------------------------|
| UsernameTooShort | | PasswordTooShort |
| UsernameTooLong | | PasswordTooLong |
| UsernameContainsIllegal...| | PasswordMissingCharacter.. |
+---------------------------+ +----------------------------+
- Length: 3β16 characters
- Allowed characters: letters, digits, underscore
- Custom error for illegal characters, short or long input
- Length: 8β40 characters
- Must contain:
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least one special character
python main.pyFollow the prompts and fix any errors returned until login is successful.
To isolate dependencies and work in a clean environment:
# Create virtual environment
python -m venv venv
# Activate it (Windows)
venv\Scripts\activate
# Activate it (Linux/macOS)
source venv/bin/activate
# Install any needed packages (if applicable)
pip install -r requirements.txt
# To save dependencies
pip freeze > requirements.txtDon't forget to add
venv/to your.gitignoreto avoid pushing it to GitHub.
Please enter your 'Username': da@vid
Username Problem: Username "da@vid" includes illegal character '@' at index 2.
Please enter your 'Password': 12345
Password problem: Password "12345" is too short, should be at least 8 characters long
Please enter your 'Password': David123
Password problem: Password is missing a required character type (Special)
You are logged-in successfully!
MIT License. Free to use, distribute, and modify.