欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP生成隨機(jī)密碼類分享

 更新時間:2014年06月25日 09:12:54   投稿:junjie  
這篇文章主要介紹了PHP生成隨機(jī)密碼類分享,生成的密碼包含大小寫英文字母及數(shù)字,需要的朋友可以參考下

類代碼:

<?php
/**
 * PHP - Password Generator Class
 * Version 1.0.0
 *
 */
 
if (@!is_object($passGen) || !isset($passGen)) {
  $passGen = new Password;
}
 
class Password
{
 
  /**
   * 大寫字母 A-Z
   *
   * @var array
   */
  protected $uppercase_chars;
 
  /**
   * 小寫字母 a-z
   *
   * @var array
   */
  protected $lowercase_chars;
 
  /**
   * 阿拉伯?dāng)?shù)字 0-9
   *
   * @var array
   */
  protected $number_chars;
 
  /**
   * 特殊字符
   *
   * @var array
   */
  protected $special_chars;
 
  /**
   * 其他特殊字符
   *
   * @var array
   */
  protected $extra_chars;
 
  /**
   * 最終用來生成密碼的所有字符
   *
   * @var array
   */
  protected $chars = array();
 
  /**
   * 密碼長度
   *
   * @var array
   */
  public $length;
 
  /**
   * 是否使用大寫字母
   *
   * @var boolean
   */
  public $uppercase;
 
  /**
   * 是否使用小寫字母
   *
   * @var boolean
   */
  public $lowercase;
 
  /**
   * 是否使用阿拉伯?dāng)?shù)字
   *
   * @var boolean
   */
  public $number;
 
  /**
   * 是否使用特殊字符
   *
   * @var boolean
   */
  public $special;
 
  /**
   * 是否使用額外的特殊字符
   *
   * @var boolean
   */
  public $extra;
 
  /**
   * 初始化密碼設(shè)置
   *
   * @param int $length
   */
  function Password($length = 12)
  {
    $this->length = $length;
     
    $this->configure(true, true, true, false, false);
  }
 
  /**
   * 配置
   */
  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_chars);
    }
    if (($this->lowercase = $lowercase) === true) {
      $this->chars = array_merge($this->chars, $this->lower_chars);
    }
    if (($this->number = $number) === true) {
      $this->chars = array_merge($this->chars, $this->number_chars);
    }
    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);
  }
   
  /**
   * 從字符列中生成隨機(jī)密碼
   *
   * @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;
  }
 
  /**
   * 生成隨機(jī)數(shù)字
   *
   * @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));
  }
}

調(diào)用:

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

相關(guān)文章

  • PHP實現(xiàn)的帶超時功能get_headers函數(shù)

    PHP實現(xiàn)的帶超時功能get_headers函數(shù)

    這篇文章主要介紹了PHP實現(xiàn)的帶超時功能的get_headers函數(shù),本文直接給出實現(xiàn)代碼,需要的朋友可以參考下
    2015-02-02
  • Discuz7.2版的faq.php SQL注入漏洞分析

    Discuz7.2版的faq.php SQL注入漏洞分析

    這篇文章主要介紹了Discuz7.2版的faq.php SQL注入漏洞分析,包含注入代碼和源碼分析,需要的朋友可以參考下
    2014-08-08
  • PHP那些瑣碎的知識點(整理)

    PHP那些瑣碎的知識點(整理)

    今天小編給大家分享php那些瑣碎的知識點,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-05-05
  • Yii2實現(xiàn)ActiveForm ajax提交

    Yii2實現(xiàn)ActiveForm ajax提交

    這篇文章主要 為大家詳細(xì)介紹了Yii2實現(xiàn)ActiveForm ajax提交的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • PHP一個簡單的無需刷新爬蟲

    PHP一個簡單的無需刷新爬蟲

    今天小編就為大家分享一篇關(guān)于PHP一個簡單的無需刷新爬蟲,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • php file_get_contents函數(shù)輕松采集html數(shù)據(jù)

    php file_get_contents函數(shù)輕松采集html數(shù)據(jù)

    PHP手冊里是這么解釋的:file_get_contents — 將整個文件讀入一個字符串,于是可以很容易的獲取其他站的信息,再用正則加以變換,再做一些判斷和設(shè)定,就OK了,不多說了,放代碼,我基本都做了解釋的。
    2010-04-04
  • 提高php編程效率技巧

    提高php編程效率技巧

    php是全球范圍應(yīng)用范圍最廣的開發(fā)語言,php和linux、apache、mysql緊密結(jié)合,形成了lamp的開源黃金搭檔。因其php具有開發(fā)周期短、免費、穩(wěn)定、安全、簡單易學(xué)、跨平臺等優(yōu)勢,被評為最受歡迎的編程語言,下面小編給大家整理了提高php編程效率的20個要點,需要的可以參考
    2015-08-08
  • 詳解Yii2高級版引入bootstrap.js的一個辦法

    詳解Yii2高級版引入bootstrap.js的一個辦法

    本篇文章主要介紹了詳解Yii2高級版引入bootstrap.js的一個辦法,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Laravel5.1 框架數(shù)據(jù)庫操作DB運行原生SQL的方法分析

    Laravel5.1 框架數(shù)據(jù)庫操作DB運行原生SQL的方法分析

    這篇文章主要介紹了Laravel5.1 框架數(shù)據(jù)庫操作DB運行原生SQL的方法,結(jié)合實例形式分析了laravel5.1使用DB運行原生SQL的相關(guān)操作技巧與注意事項,需要的朋友可以參考下
    2020-01-01
  • smarty中常用方法實例總結(jié)

    smarty中常用方法實例總結(jié)

    這篇文章主要介紹了smarty中常用方法,較為詳細(xì)的分析了smarty模板中較為常用的方法、屬性及環(huán)境變量等使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08

最新評論