Пример #1
0
 function testLargeRandoms()
 {
     $min = 1 << 30;
     $max = $min + (1 << 33) + 17;
     $rand = auth_random($min, $max);
     $this->assertTrue($rand >= $min, 'The generated number was too low');
     $this->assertTrue($rand <= $max, 'The generated number was too high');
 }
Пример #2
0
/**
 * Create a pronouncable password
 *
 * The $foruser variable might be used by plugins to run additional password
 * policy checks, but is not used by the default implementation
 *
 * @author   Andreas Gohr <*****@*****.**>
 * @link     http://www.phpbuilder.com/annotate/message.php3?id=1014451
 * @triggers AUTH_PASSWORD_GENERATE
 *
 * @param  string $foruser username for which the password is generated
 * @return string  pronouncable password
 */
function auth_pwgen($foruser = '')
{
    $data = array('password' => '', 'foruser' => $foruser);
    $evt = new Doku_Event('AUTH_PASSWORD_GENERATE', $data);
    if ($evt->advise_before(true)) {
        $c = 'bcdfghjklmnprstvwz';
        //consonants except hard to speak ones
        $v = 'aeiou';
        //vowels
        $a = $c . $v;
        //both
        $s = '!$%&?+*~#-_:.;,';
        // specials
        //use thre syllables...
        for ($i = 0; $i < 3; $i++) {
            $data['password'] .= $c[auth_random(0, strlen($c) - 1)];
            $data['password'] .= $v[auth_random(0, strlen($v) - 1)];
            $data['password'] .= $a[auth_random(0, strlen($a) - 1)];
        }
        //... and add a nice number and special
        $data['password'] .= auth_random(10, 99) . $s[auth_random(0, strlen($s) - 1)];
    }
    $evt->advise_after();
    return $data['password'];
}
Пример #3
0
 /**
  * Use DokuWiki's secure random generator if available
  *
  * @param int $min
  * @param int $max
  * @return int
  */
 protected function random($min, $max)
 {
     if (function_exists('auth_random')) {
         return auth_random($min, $max);
     } else {
         return mt_rand($min, $max);
     }
 }