File: |
src/PasswordHelper/Generator.php |
Role: |
Class source |
Content type: |
text/plain |
Description: |
Class source |
Class: |
PHP Password Validation Helper
Generate and check a password according to rules |
Author: |
By John Conde |
Last change: |
refactor: break down Generator::generate() into smaller methods
- Split generate() method into smaller, focused methods for better maintainability:
- validateCharacterTypes(): Validates character type selection
- buildCharacterPool(): Creates character pool based on selected types
- generateRequiredCharacters(): Ensures required character types
- fillRemainingCharacters(): Fills remaining password length
- Added comprehensive unit tests for new private methods
- Improved code readability and maintainability
- Maintained existing functionality while reducing method complexity
- All tests passing (55 tests, 125 assertions)
This refactoring makes the code more modular and easier to maintain while
preserving the original password generation logic and security requirements.
refactor: minor code cleanup
refactor: update codebase for PHP 8.0 compatibility
- Updated test cases in PolicyTest, ValidatorTest, and GeneratorTest to match the new class interfaces and expectations.
- Added getter methods for minLength and maxLength in the Generator class.
- Updated assertions in GeneratorTest to use PHPUnit 8.5 compatible methods.
- Adjusted test expectations in ValidatorTest to align with the current validation logic.
This refactoring ensures that the codebase is fully compatible with PHP 8.0 while maintaining the intended functionality and test coverage.
feat: Refactor password strength scoring to use a 1-100 scale
This commit introduces a comprehensive scoring system for password strength, replacing the previous categorical approach. The new system evaluates passwords based on four key factors:
- Length (up to 30 points): Rewards passwords between 8 and 20 characters.
- Character Variety (up to 30 points): Awards points for using uppercase, lowercase, numbers, and special characters, with bonuses for mixed case and multiple character types.
- Complexity (up to 20 points): Checks for repeated characters, sequential patterns, common passwords, and dictionary words.
- Entropy (up to 20 points): Calculates password entropy based on character set size and length.
Key improvements:
- Early returns for empty and very short passwords (score of 1)
- Robust checks for common patterns and keyboard sequences
- Comprehensive test suite using data providers
- Type-safe implementation with strict return types
The scoring system now provides a more granular and accurate assessment of password strength, making it easier to enforce security policies and guide users toward stronger passwords.
Tests: 60 tests, 114 assertions
Improve docblocks, restore Validator compatibility, and fix Generator return types
- Enhanced docblock comments for all classes in src/PasswordHelper to be more descriptive and PSR-12 compliant.
- Fixed Generator::getRandomCharacter() to always return a string, preventing type errors.
- Reintroduced protected meetsMinimum* methods in Validator to support legacy and test code.
Added PHP Documentor support
|
Date: |
7 days ago |
Size: |
6,960 bytes |
|
|
|