PasswordHasher
in package
Password hashing and validation utility.
Uses PHP's native password_hash() with Argon2id algorithm for secure password storage and verification.
Table of Contents
Properties
- $_minLength : int
- $_requireLowercase : bool
- $_requireNumbers : bool
- $_requireSpecialChars : bool
- $_requireUppercase : bool
Methods
- configure() : self
- Configure password requirements from settings
- getValidationErrors() : array<int, string>
- Get password validation error messages
- hash() : string
- Hash a password using Argon2id or Bcrypt
- meetsRequirements() : bool
- Check if password meets strength requirements
- needsRehash() : bool
- Check if a hash needs to be rehashed (algorithm upgrade)
- setMinLength() : self
- Set minimum password length
- setRequireLowercase() : self
- Set whether lowercase letters are required
- setRequireNumbers() : self
- Set whether numbers are required
- setRequireSpecialChars() : self
- Set whether special characters are required
- setRequireUppercase() : self
- Set whether uppercase letters are required
- verify() : bool
- Verify a password against a hash
Properties
$_minLength
private
int
$_minLength
= 8
$_requireLowercase
private
bool
$_requireLowercase
= true
$_requireNumbers
private
bool
$_requireNumbers
= true
$_requireSpecialChars
private
bool
$_requireSpecialChars
= false
$_requireUppercase
private
bool
$_requireUppercase
= true
Methods
configure()
Configure password requirements from settings
public
configure(array<string, mixed> $settings) : self
Parameters
- $settings : array<string, mixed>
Return values
selfgetValidationErrors()
Get password validation error messages
public
getValidationErrors(string $password) : array<int, string>
Parameters
- $password : string
Return values
array<int, string>hash()
Hash a password using Argon2id or Bcrypt
public
hash(string $password) : string
Parameters
- $password : string
Return values
stringmeetsRequirements()
Check if password meets strength requirements
public
meetsRequirements(string $password) : bool
Parameters
- $password : string
Return values
boolneedsRehash()
Check if a hash needs to be rehashed (algorithm upgrade)
public
needsRehash(string $hash) : bool
Parameters
- $hash : string
Return values
boolsetMinLength()
Set minimum password length
public
setMinLength(int $minLength) : self
Parameters
- $minLength : int
Return values
selfsetRequireLowercase()
Set whether lowercase letters are required
public
setRequireLowercase(bool $requireLowercase) : self
Parameters
- $requireLowercase : bool
Return values
selfsetRequireNumbers()
Set whether numbers are required
public
setRequireNumbers(bool $requireNumbers) : self
Parameters
- $requireNumbers : bool
Return values
selfsetRequireSpecialChars()
Set whether special characters are required
public
setRequireSpecialChars(bool $requireSpecialChars) : self
Parameters
- $requireSpecialChars : bool
Return values
selfsetRequireUppercase()
Set whether uppercase letters are required
public
setRequireUppercase(bool $requireUppercase) : self
Parameters
- $requireUppercase : bool
Return values
selfverify()
Verify a password against a hash
public
verify(string $password, string $hash) : bool
Parameters
- $password : string
- $hash : string