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.
<?php
function cracklibCheck($password, &$message)
{
$password=str_replace("\r", "", $password);
$password=str_replace("\n", "", $password);
exec("echo ".escapeshellarg($password)." | /usr/sbin/cracklib-check 2>/dev/null", $output, $return_var);
if($return_var==0)
{
if(preg_match("/^.*\: ([^:]+)$/", $output[0], $matches))
{
if(strtoupper($matches[1])=="OK")
{
$message="";
return(true);
}
else
{
$message=$matches[1];
return(false);
}
}
else
{
throw new Exception("Didn't understand cracklib-check response.");
}
}
else
{
throw new Exception("Failed to run cracklib-check.");
}
}
?>