Neuron-PHP

IsPassword extends Base
in package

Password validator with configurable requirements.

Validates password strength based on configurable criteria including length, character types (uppercase, lowercase, digits, special characters). Provides flexible password policy enforcement for various security requirements.

Tags
example
// Simple length-only validation (minimum 8 characters)
$validator = new IsPassword( 8 );

// Complex password policy (8-64 chars, requires upper, lower, digit, special)
$validator = new IsPassword( 12, 64, true, true, true, true );

// Custom policy with specific requirements
$validator = new IsPassword(
    minLength: 10,
    maxLength: 128,
    requireUppercase: true,
    requireLowercase: true,
    requireDigit: true,
    requireSpecial: true,
    specialChars: '@#$%'
);

if( $validator->isValid( 'MyP@ssw0rd' ) ) {
    echo "Password is valid";
}

Table of Contents

Properties

$_maxLength  : int|null
$_minLength  : int
$_requireDigit  : bool
$_requireLowercase  : bool
$_requireSpecial  : bool
$_requireUppercase  : bool
$_specialChars  : string

Methods

__construct()  : void
Constructor to initialize password validation requirements.
isValid()  : bool
Returns true if validation is successful
validate()  : bool
Validates the password against configured requirements.

Properties

$_requireLowercase

private bool $_requireLowercase

$_requireUppercase

private bool $_requireUppercase

Methods

__construct()

Constructor to initialize password validation requirements.

public __construct(int $minLength[, int|null $maxLength = null ][, bool $requireUppercase = false ][, bool $requireLowercase = false ][, bool $requireDigit = false ][, bool $requireSpecial = false ][, string $specialChars = '!@#$%^&*()_+-=[]{}|;:,.<>?' ]) : void
Parameters
$minLength : int

Minimum password length (required)

$maxLength : int|null = null

Maximum password length, null for no limit (default: null)

$requireUppercase : bool = false

Require at least one uppercase letter (default: false)

$requireLowercase : bool = false

Require at least one lowercase letter (default: false)

$requireDigit : bool = false

Require at least one digit (default: false)

$requireSpecial : bool = false

Require at least one special character (default: false)

$specialChars : string = '!@#$%^&*()_+-=[]{}|;:,.<>?'

Set of allowed special characters (default: !@#$%^&*()_+-=[]}|;:,.<>?)

isValid()

Returns true if validation is successful

public isValid(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

validate()

Validates the password against configured requirements.

protected validate(mixed $value) : bool
Parameters
$value : mixed

The password to validate

Return values
bool

True if the password meets all requirements, false otherwise


        
On this page

Search results