In addition to the usual checks crack can also check for similarities between the password and a username and gecos field (the gecos field normally contains the person's full name on unix systems).
There is a third format for the function call which supplies these additional parameters:
bool crack_check (string $password, string $username, string $gecos, resource $dictionary)
This is true of PECL crack version 0.4, I'm not sure about earlier versions.
(PECL crack >= 0.1)
crack_check — Performs an obscure check with the given password
Performs an obscure check with the given password on the specified dictionary.
This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk.
The crack lib dictionary. If not specified, the last opened dictionary is used.
The tested password.
Returns TRUE if password is strong, or FALSE otherwise.
If you need to test a password with cracklib but don't have the necessary module available in PHP, you can use a function like this.
It requires the command line cracklib-check binary in /usr/sbin, but changing its location is trivial.
The $message variable will contain cracklib's complaint (if there is one)
You'll want to wrap your invocation of this function in a try...catch block.
function cracklibCheck($password, &$message)
// Clean up password
$password=str_replace("\r", "", $password);
$password=str_replace("\n", "", $password);
// Run password through cracklib-check
exec("echo ".escapeshellarg($password)." | /usr/sbin/cracklib-check 2>/dev/null", $output, $return_var);
// Check it ran properly
if(preg_match("/^.*\: ([^:]+)$/", $output, $matches))
// Check response
// Password is strong
// Cracklib doesn't like it
// Badly formatted response from cracklib-check.
throw new Exception("Didn't understand cracklib-check response.");
// Some sort of execution error
throw new Exception("Failed to run cracklib-check.");