Thursday, 13 March 2014

PHP generate password



First example
function generate($len ){
          $password = "";
          $possible = "0123456789bcdfghjkmnpqrstvwxyz";
          $i = 0;
          while ( $i < $len) {
            $char = substr($possible , mt_rand( 0, strlen ($possible)- 1), 1);
              $password .= $char;
              $i++;
          }
          return $password ;
    }

Second example
$salt ='gt|.zjxk206I0Q6p-,}_ZY!8roh6;MYl&`Pq*$BZ{}oDuCSW@>u=TtqBV}T[!)^u' ;
$PASSWORD_LENGTH =10;
$password =substr( str_shuffle(strtolower( sha1(rand () . time() . $salt ))),0, $PASSWORD_LENGTH);

No comments:

Post a Comment