Exemple #1
0
 function rule_crack($a)
 {
     $result = null;
     if (function_exists('crack_check')) {
         if (!crack_check($a)) {
             return $this->fail('Bad password - ' . crack_getlastmessage());
         }
         return;
     }
     $res = $this->checkByCrackLib($a);
     if ($res === true) {
         return;
     }
     return $this->fail('Bad password - ' . $res);
 }
 /**
  * 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)));
     }
 }
/**
 * checks password with cracklib and outputs warning message if insecure.
 *
 * @param string username
 * @param string password
 */
function liveuser_admin_users_cracklib_check($username, $password)
{
    if (extension_loaded('crack') && function_exists('crack_check') && function_exists('crack_getlastmessage')) {
        crack_check($value);
        if (crack_getlastmessage() != "strong password") {
            echo '<p>Password for user ' . $username . ' is not secure, cracklib reports: ' . crack_getlastmessage() . '.</p>';
        }
    }
    //Jeff's password checker, copied from auth_liveuser.php
    $password_status = ewiki_check_passwd($password, $username);
    //$end=getmicrotime();
    //echo($end-$time);
    if ($password_status != 'good passwd') {
        if ($password_status == 'read error') {
            echo ewiki_t('PASS_DICTIONARY_READ_ERROR');
        } else {
            echo ewiki_t($password_status);
        }
    }
}
Exemple #4
0
<?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);
?>