栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

PHP生成随机密码类分享

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP生成随机密码类分享

类代码:

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);
  }
   
  
  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;
  }
 
  
  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));
  }
}

调用:

generate();
 
//FS4yq74e2LeE

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/47878.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号