Generates a memorable passphrase from a built-in dictionary of 150 distinct English words.
$words: Number of words (1 to 32, default 4)
$separator: String placed between words (default "-")
$capitalize: Capitalize the first letter of each word (default false)
$include_number: Append a random 2-digit number to one of the words (default false)
Error Handling
All functions validate their inputs and throw an Exception prefixed with password::
password_generate(0) or password_generate(2000) -> password: length must be between 1 and 1024
password_generate(12, ["lower" => false, "upper" => false, "digits" => false, "symbols" => false]) -> password: character set cannot be empty; enable at least one character class
password_generate(12, ["custom" => ""]) -> password: custom character set cannot be empty
password_generate(2, ["require_each" => true]) -> password: length (2) is smaller than the number of required character classes (4)
password_passphrase(0) or password_passphrase(40) -> password: word count must be between 1 and 32
Examples
01Quick start
Bundled with the compiler — import "password"; works offline in any file, or add it to a project with hphp install password.