Skip to main content

A Python library for validating passwords with customizable rules.

Project description

FortiPassValidator

FortiPassValidator is a Python library for validating passwords against customizable rules. It helps ensure that passwords are strong, meet complexity requirements, and avoid inappropriate language.

Features

  • Validate password length, uppercase, lowercase, numbers, and special characters.
  • Detect inappropriate language in passwords using the profanity-check library.
  • Fully customizable validation settings.
  • Lightweight and easy to integrate into your projects.

Installation

Install the library using pip:

pip install FortiPassValidator

Usage

Default Settings

By default, FortiPassValidator enforces the following rules:

  • Minimum length: 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one numeric digit
  • At least one special character

Example:

from fortipass import FortiPassValidator

validator = FortiPassValidator()

password = "ValidPass123!"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: True, Feedback: Password is valid.

Customizing Validation Rules

You can adjust the validation rules to fit your requirements:

  • Custom Minimum Length: Enforce a minimum length of 12 characters.
validator = FortiPassValidator(min_length=12)
password = "Short1!"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: False, Feedback: Password must be at least 12 characters long.
  • Disabling Uppercase Requirement: Allow passwords without uppercase letters.
validator = FortiPassValidator(require_upper=False)
password = "lowercase123!"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: True, Feedback: Password is valid.
  • Disabling Special Characters Requirement: Allow passwords without special characters.
validator = FortiPassValidator(require_special=False)
password = "Password123"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: True, Feedback: Password is valid.

Profanity Detection

FortiPassValidator detects inappropriate language in passwords using the profanity-check library. This ensures that offensive words are flagged during validation.

Example:

password = "Badword123!"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: False, Feedback: Password contains inappropriate language.

All Rules Disabled

If you want minimal validation (e.g., for testing purposes), you can disable all rules:

validator = FortiPassValidator(min_length=1, require_upper=False, require_lower=False, require_numbers=False, require_special=False)
password = "a"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: True, Feedback: Password is valid.

Comprehensive Validation

You can combine multiple rules to create a highly secure validation setup:

validator = FortiPassValidator(min_length=16, require_upper=True, require_lower=True, require_numbers=True, require_special=True)
password = "SuperSecure123!"
is_valid, feedback = validator.validate(password)
print(f"Valid: {is_valid}, Feedback: {feedback}")
# Output: Valid: True, Feedback: Password is valid.

Testing

To test the library, use the provided unit tests in the tests directory. Run the following command:

python -m unittest discover tests

Project Structure

FortiPassValidator/
├── fortipass/
│   ├── __init__.py
│   ├── validator.py
├── tests/
│   ├── test_validator.py
├── setup.py
├── requirements.txt
├── README.md
├── LICENSE

Dependencies

  • profanity-check: Used to detect inappropriate language in passwords.

To install dependencies, run:

pip install -r requirements.txt

Contribution

Contributions are welcome! Follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and test them.
  4. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Author

Ahmed Abdelrahman

Example Use Cases

Web Applications

Enforce strong password policies during user registration and account updates.

Internal Tools

Validate passwords for employees or system administrators to ensure they follow best practices.

Educational Projects

Demonstrate password security concepts and secure coding practices.

Command-Line Tools

Integrate FortiPassValidator into CLI tools to check password strength in bulk or interactively.

FAQ

1. What happens if profanity-check doesn’t recognize a language?

  • The profanity-check library works well with English. For other languages, you may need to integrate additional profanity-detection tools.

2. Can I disable profanity detection?

  • Yes, you can remove or replace the profanity-check logic in the validate method if it is not required for your use case.

3. Is the library thread-safe?

  • Yes, the library is designed to be thread-safe.

4. How do I report bugs or request features?


Thank you for using FortiPassValidator! Feel free to contribute or reach out with questions.

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

fortipassvalidator-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

FortiPassValidator-1.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file fortipassvalidator-1.0.0.tar.gz.

File metadata

  • Download URL: fortipassvalidator-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for fortipassvalidator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b15c7df825b3f4e41e964d90d0c54155f9a67d2e1325c6c2c35e0738331ce7f2
MD5 dd04cb56038a7687b1af0aebda4fce3b
BLAKE2b-256 d1c5394585f44048541e0cdd5c328c6b63092250fc19ff84b3ef47abed171e08

See more details on using hashes here.

File details

Details for the file FortiPassValidator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for FortiPassValidator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af0ae03e1e63aabd84af9fbd77b63f50cc6c57bbe7c12004b960a9872cdbe940
MD5 2a60845d7a580b08ba27744992031cbc
BLAKE2b-256 1502abc5175a56a9958b7af4dd9229e7ba1060acefb5f8455fae5dd6706f8b43

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