PasswordHasher
in package
Service for password hashing and verification.
This is a thin wrapper around PasswordService to provide a convenient interface for common password operations.
Tags
Table of Contents
Properties
- $service : PasswordService
- Underlying password service.
Methods
- __construct() : mixed
- Create a new PasswordHasher.
- generateToken() : string
- Generate a secure random token.
- hash() : string
- Hash a password.
- needsRehash() : bool
- Check if a hash needs to be rehashed.
- validateStrength() : array{valid: bool, errors: string[]}
- Validate password strength.
- verify() : bool
- Verify a password against a hash.
Properties
$service
Underlying password service.
private
PasswordService
$service
Methods
__construct()
Create a new PasswordHasher.
public
__construct([PasswordService|null $service = null ]) : mixed
Parameters
- $service : PasswordService|null = null
-
Optional password service
generateToken()
Generate a secure random token.
public
generateToken([int<1, max> $length = 32 ]) : string
Parameters
- $length : int<1, max> = 32
-
Token length in bytes
Return values
string —The generated token
hash()
Hash a password.
public
hash(string $password) : string
Parameters
- $password : string
-
The plain-text password
Return values
string —The hashed password
needsRehash()
Check if a hash needs to be rehashed.
public
needsRehash(string $hash) : bool
Parameters
- $hash : string
-
The hash to check
Return values
bool —True if rehash is needed
validateStrength()
Validate password strength.
public
validateStrength(string $password) : array{valid: bool, errors: string[]}
Parameters
- $password : string
-
The password to validate
Return values
array{valid: bool, errors: string[]} —Validation result
verify()
Verify a password against a hash.
public
verify(string $password, string $hash) : bool
Parameters
- $password : string
-
The plain-text password
- $hash : string
-
The hash to verify against
Return values
bool —True if the password matches