-
Notifications
You must be signed in to change notification settings - Fork 0
passHash
Secures user passwords by prefixing them with a cryptographic salt and hashing the combined value. This method delegates algorithm validation and fallback handling entirely to the core hash() method, keeping the implementation simple and incredibly secure.
passHash(string $pw, string $salt, ?string $algo = null): string
pw (string) : The plaintext password to be hashed. Cannot be empty.
salt (string) : A unique cryptographic salt to prefix to the password. Cannot be empty.
algo (string|null)
: A specific hashing algorithm to use. Case-insensitive. If null, the currently set algorithm or class default is used. (default: null) ^(optional)^
(string) : Returns the combined hashed password and salt.
📌 To ensure maximum security, this method strictly enforces the presence of both a password and a salt.
If the password is empty and the exception is suppressed, it returns a safe, non-bypassable, randomized
error_hex string.If the salt is empty it is treated as a failure and the method will halt, or safely return a randomized
error_hex string to prevent weak, unsalted password hashes from ending up in your database.If an invalid algorithm name is passed (e.g.,
'sha2560'), the validation failure is caught and handled seamlessly downstream by thehash()method.
- Standard Salted Password Hashing
Uses your primary configured class algorithm.
$sec->passHash('password', 'salt');
// Result (using default sha256): "13601bda4ea78e55a07b98866d2be6be..."
- Specific Hashing Algorithm Override
Hashes the salted password using a specific algorithm (e.g., md5) on the fly.
$sec->passHash('password', 'salt', 'md5');
// Result (using md5): "67a1e09bb1f83f50..."
- Handling Empty Parameter Failures (Suppressed Exception)
If an empty password is passed and the exception is caught or suppressed, a safe, unique token is returned:
$sec->passHash('', 'salt');
// Result: "error_5f18c642ad91bc1b47df1120409fe6923cf992fa..."
| Config Key | Default Value | Allowed Values | Description |
|---|---|---|---|
| algorithm | sha256 | string (See: ) | Default hashing algorithm. |
- Throws an exception if the password is empty.
- Triggers a warning if the salt is empty.
Home | CoreySecurity | Hashing