/** * Check that a password is valid and secure * * @param string $passwd the password to check * * @return boolean is the password valid and secure? * * @throws Exception when password is invalid/insecure */ public function validate_password($passwd) { $dict_loc = ini_get('crack.default_dictionary'); if (function_exists('crack_check') && $dict_loc) { $dict = crack_opendict($dict_loc); if (!crack_check($passwd)) { throw new Exception(crack_getlastmessage()); } return true; } else { $_error = array(); switch ($GLOBALS['phpgw_info']['server']['password_level']) { default: case 'NONALPHA': $_error[] = self::_validate_password_level_nonalpha($passwd); // fall through // fall through case '1NUM': $_error[] = self::_validate_password_level_1num($passwd); // fall through // fall through case '2LOW': $_error[] = self::_validate_password_level_2low($passwd); // fall through // fall through case '2UPPER': $_error[] = self::_validate_password_level_2upper($passwd); // fall through // fall through case '8CHAR': $_error[] = self::_validate_password_level_8char($passwd); } } $error = array(); foreach ($_error as $_msq) { if ($_msq) { $error[] = $_msq; } } if ($error) { throw new Exception(implode('<br/>', array_reverse($error))); } }
<?php $pswd = "567hejk39"; /* Open the dictionary. Note that the dictionary filename does NOT include the extension. */ $dictionary = crack_opendict('/usr/lib/cracklib_dict'); // Check password for guessability $check = crack_check($dictionary, $pswd); // Retrieve outcome echo crack_getlastmessage(); // Close dictionary crack_closedict($dictionary); ?>