示例#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);
 }
示例#2
0
function cracklib_checkpw($pw, $addwords)
{
    global $opt;
    // length min. 6 chars
    if (strlen($pw) < 6) {
        return false;
    }
    // min. 4 different chars
    $chars = array();
    for ($i = 0; $i < mb_strlen($pw); $i++) {
        $chars[mb_substr($pw, $i, 1)] = true;
    }
    if (count($chars) <= 4) {
        return false;
    }
    unset($chars);
    // prepare $addwords
    $wordlist = array();
    foreach ($addwords as $word) {
        $word = mb_strtolower($word);
        $word = mb_ereg_replace('\\?', ' ', $word);
        $word = mb_ereg_replace('\\)', ' ', $word);
        $word = mb_ereg_replace('\\(', ' ', $word);
        $word = mb_ereg_replace('\\.', ' ', $word);
        $word = mb_ereg_replace('´', ' ', $word);
        $word = mb_ereg_replace('`', ' ', $word);
        $word = mb_ereg_replace('\'', ' ', $word);
        $word = mb_ereg_replace('/', ' ', $word);
        $word = mb_ereg_replace(':', ' ', $word);
        $word = mb_ereg_replace('-', ' ', $word);
        $word = mb_ereg_replace(',', ' ', $word);
        $word = mb_ereg_replace("\r\n", ' ', $word);
        $word = mb_ereg_replace("\n", ' ', $word);
        $word = mb_ereg_replace("\r", ' ', $word);
        $wordlist = array_merge($wordlist, mb_split(' ', $word));
    }
    foreach ($wordlist as $k => $v) {
        if (mb_strlen($v) < 3) {
            unset($wordlist[$k]);
        }
    }
    $pw_lc = mb_strtolower($pw);
    // $pw may not contain one of $addwords[]
    foreach ($wordlist as $v) {
        if (mb_strpos($pw_lc, $v) !== false) {
            return false;
        }
    }
    // one of $addwords[] may not contain $pw
    foreach ($wordlist as $v) {
        if (mb_strpos($v, $pw_lc) !== false) {
            return false;
        }
    }
    if ($opt['logic']['cracklib'] == true) {
        // load cracklib
        if (!function_exists('crack_check')) {
            @dl('crack.so');
        }
        // cracklib loaded?
        if (function_exists('crack_check')) {
            if (!crack_check($pw)) {
                return false;
            }
        }
    }
    return true;
}
示例#3
0
function cracklib_checkpw($pw, $addwords)
{
    global $opt;
    // length min. 6 chars
    if (strlen($pw) < 6) {
        return false;
    }
    // min. 4 different chars
    $chars = array();
    for ($i = 0; $i < mb_strlen($pw); $i++) {
        $chars[mb_substr($pw, $i, 1)] = true;
    }
    if (count($chars) <= 4) {
        return false;
    }
    unset($chars);
    // prepare $addwords
    $wordlist = array();
    foreach ($addwords as $word) {
        $word = mb_strtolower($word);
        $word = mb_ereg_replace('\\?', ' ', $word);
        $word = mb_ereg_replace('\\)', ' ', $word);
        $word = mb_ereg_replace('\\(', ' ', $word);
        $word = mb_ereg_replace('\\.', ' ', $word);
        $word = mb_ereg_replace('´', ' ', $word);
        $word = mb_ereg_replace('`', ' ', $word);
        $word = mb_ereg_replace('\'', ' ', $word);
        $word = mb_ereg_replace('/', ' ', $word);
        $word = mb_ereg_replace(':', ' ', $word);
        $word = mb_ereg_replace('-', ' ', $word);
        $word = mb_ereg_replace(',', ' ', $word);
        $word = mb_ereg_replace("\r\n", ' ', $word);
        $word = mb_ereg_replace("\n", ' ', $word);
        $word = mb_ereg_replace("\r", ' ', $word);
        $wordlist = array_merge($wordlist, mb_split(' ', $word));
    }
    foreach ($wordlist as $k => $v) {
        if (mb_strlen($v) < 3) {
            unset($wordlist[$k]);
        }
    }
    $pw_lc = mb_strtolower($pw);
    // $pw may not contain one of $addwords[]
    foreach ($wordlist as $v) {
        if (mb_stripos($pw_lc, $v) !== false) {
            // mb_stripos needs PHP 5.2
            return false;
        }
    }
    // one of $addwords[] may not contain $pw
    foreach ($wordlist as $v) {
        if (mb_stripos($v, $pw_lc) !== false) {
            return false;
        }
    }
    // words from pw library are not allowed
    if (sql_value("SELECT COUNT(*) FROM `pw_dict` WHERE `pw`='&1'", 0, $pw) > 0) {
        return false;
    }
    if ($opt['logic']['cracklib'] == true) {
        // load cracklib
        if (!function_exists('crack_check')) {
            try {
                dl('crack.so');
            } catch (Exception $e) {
                // @todo implement logging
            }
        }
        // cracklib loaded?
        if (function_exists('crack_check')) {
            if (!crack_check($pw)) {
                return false;
            }
        }
    }
    return true;
}
示例#4
0
/**
 * 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);
        }
    }
}
 /**
  * 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)));
     }
 }
示例#6
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);
?>