PHP generate random password class sharing _php tutorial

Source: Internet
Author: User
Class Code:

<?php/** * Php-password Generator Class * Version 1.0.0 * */if (@!is_object ($passGen) | |!isset ($passGen)) {$passG En = new Password;}   Class password{/** * Capital Letter A-Z * * @var array */protected $uppercase _chars;   /** * lowercase letter A-Z * * @var array */protected $lowercase _chars;   /** * Arabic numerals 0-9 * * @var array */protected $number _chars;   /** * Special Characters * * @var array */protected $special _chars;   /** * Other Special characters * * @var array */protected $extra _chars;   /** * All characters that are eventually used to generate the password * * @var array */protected $chars = Array ();   /** * Password Length * * @var array */public $length;   /** * Whether to use uppercase letters * * @var Boolean */public $uppercase;   /** * Whether to use lowercase * * @var boolean */public $lowercase;   /** * Whether to use Arabic numerals * * @var Boolean */public $number;   /** * Whether to use special characters * * @var Boolean */public $special;   /** * Whether to use extra special characters * * @var Boolean */public $extra; /** * Initialize Password settings * * @param int $lengtH * * Function Password ($length =) {$this->length = $length;  $this->configure (True, True, True, false, false); }/** * Config * * Function Configure ($uppercase = False, $lowercase = False, $number = false, $special = FAL     SE, $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_cha    RS); } if (($this->lowercase = $lowercase) = = = True) {$this->chars = Array_merge ($this->chars, $this->lowe    R_chars); } if (($this->number = $number) = = = True) {$this->chars = Array_merge ($this->chars, $this->number_cha    RS); } if (($this->special = $special) = = = True) {$this->chars = Array_merge ($this->chars, $this->special_    chars); } if (($this->extra = $extra) = = = True) {$this->chars = Array_merge ($this->chars, $this->extra_chars)    ;  } $this->chars = Array_unique ($this->chars); /** * Generate random password from Word 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 random numbers * * @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 ABS (Intval ($value)); }}

Call:

<?php include_once ' password.class.php '; echo $passGen->generate (); Fs4yq74e2lee

http://www.bkjia.com/PHPjc/824818.html www.bkjia.com true http://www.bkjia.com/PHPjc/824818.html techarticle Class Code: php/** * Php-password Generator class * Version 1.0.0 * */if (@!is_object ($passGen) | |!isset ($passGen)) {$pa Ssgen = new Password;} Class password{/** * Uppercase ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.