XI. Crack functions

These functions allow you to use the CrackLib library to test the 'strength' of a password. In order to use these functions, you must compile PHP with Crack support by using the --with-crack[=DIR] option.

More information regarding CrackLib along with the library can be found at http://www.users.dircon.co.uk/~crypto/.

Cracklib is useful in testing the 'strength' of a password that checks length, use of upper and lower case and a check against the specified CrackLib dictionary. CrackLib will also give helpful diagnostic messages that will help 'strengthen' the password.

This example shows how to open a CrackLib dictionary, test a given password, retrieve any diagnostic messages, and close the dictionary.

Example 1. CrackLib example

<?php
// Open CrackLib Dictionary
$dictionary = crack_opendict('/usr/local/lib/pw_dict')
     or die('Unable to open CrackLib dictionary');

// Perform password check
$check = crack_check($dictionary, 'gx9A2s0x');

// Retrieve messages
$diag = crack_getlastmessage();
echo $diag; // 'strong password'

// Close dictionary
crack_closedict($dictionary);
?>

Note: If crack_check() returns TRUE, crack_getlastmessage() will return 'strong password'.

Table of Contents
crack_opendict -- Opens a new CrackLib dictionary
crack_closedict -- Closes an open CrackLib dictionary
crack_check -- Performs an obscure check with the given password
crack_getlastmessage -- Returns the message from the last obscure check