]> dev.renevier.net Git - syj.git/blob - library/pwdgen.php
version 0.1
[syj.git] / library / pwdgen.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 namespace pwdgen;
6
7 class PwdGenerator {
8     protected static $_allowed = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
9     public static function generate($length = 8, $allowed = null) {
10         if (!$allowed or !is_string($allowed)) {
11             $allowed = self::$_allowed;
12         }
13
14         return array_reduce(range(0, $length), function($res) use ($allowed) {
15             return $res . $allowed[mt_rand(0,strlen($allowed) - 1)];
16         }, "");
17     }
18 }