<?php/** * Php-password Generator Class * Version 1.0.0 * */if (@!is_object ($passGen) | |!isset ($passGen)) {
$passGen = new Password;
Class Password {/** * Capital letter A-Z * * @var array */protected $uppercase _chars;
/** * lowercase letter A-Z * * @var array */protected $lowercase _chars;
/** * Arabic numeral 0-9 * * @var array/protected $number _chars;
/** * Special Character * * @var array/protected $special _chars;
/** * Other Special characters * * @var array/protected $extra _chars;
/** * All characters that are ultimately used to generate a password * * @var array */protected $chars = Array ();
/** * Password Length * * @var array/public $length;
/** * Use capital Letter * * @var boolean/public $uppercase;
/** * Use lowercase letter * * @var boolean/public $lowercase;
/** * The use of Arabic numerals * * @var boolean/public $number;
/** * Use special characters * * @var boolean/public $special; /** * Whether to useExtra special Characters * * @var boolean/public $extra;
/** * Initialization Password setting * * @param int $length/function Password ($length = a) {$this->length = $length;
$this->configure (True, True, True, false, false); /** * Configure/function Configure ($uppercase = False, $lowercase = False, $number = False, $special
= False, $extra = False) {$this->chars = array (); $this->upper_chars = Array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "
L "," M "," N "," O "," P "," Q "," R "," S "," T "," U "," V "," W "," X "," Y "," Z "); $this->lower_chars = Array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "
L "," M "," N "," O "," P "," Q "," R "," s "," T "," U "," V "," w "," X "," Y "," z "); $this->number_chars = Array ("1", "2", "3", "4", "5", "6", "7", "8", "9","0");
$this->special_chars = Array ("!", "@", "#", "$", "%", "^", "&", "*", "(", ")"); $this->extra_chars = Array ("[", "]", "{", "}", "-", "_", "+", "=", "<", ""
;", "?", "/", "`", "~", "|", ",", ".", ";", ":"
); if (($this->uppercase = $uppercase) = = True) {$this->chars = Array_merge ($this->chars, $this->upper_ch
ARS); } if ($this->lowercase = $lowercase) = = True) {$this->chars = Array_merge ($this->chars, $this->lo
Wer_chars); } if ($this->number = $number) = = True) {$this->chars = Array_merge ($this->chars, $this->number_c
HARs); } if ($this->special = $special) = = True) {$this->chars = Array_merge ($this->chars, $this->specia
L_chars); } if ($this->extra = $extra) = = True) {$this->chars = Array_merge ($this->chars, $this->extra_chars);
} $this->chars = Array_unique ($this->chars);
/** * Generate random passwords from character columns * * @return string **/function Generate () {if (Empty ($this->chars)) {
return false;
} $hash = ';
$totalChars = count ($this->chars)-1;
for ($i = 0; $i < $this->length; $i + +) {$hash. = $this->chars[$this->random (0, $totalChars)];
return $hash;
/** * Generates a random number * * @return int/function random ($min = 0, $max = 0) {$max _random = 4294967295;
$random = Uniqid (Microtime (). Mt_rand (), true);
$random = SHA1 (MD5 ($random));
$value = substr ($random, 0, 8);
$value = ABS (Hexdec ($value));
if ($max!= 0) {$value = $min + ($max-$min + 1) * $value/($max _random + 1);
Return to ABS (Intval ($value)); }
}