PHP 密码生成器 计算生成时间

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//PHP生成随机密码,并计算所用时间 结束时间-开始时间
class  Suijimima extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->helper(array('form', 'url','base','captcha','curl')); //鍔犺浇杈呭姪鍑芥暟
        $this->load->model('db_model');
        $this->load->library('session');
      
    }
    
  public function index(){

// 记录开始时间  
$time_start = $this->getmicrotime();  
  
// 这里放要执行的PHP代码,如:  



echo $this->create_password(5);  
echo '<hr/>'; 
echo  $this->generate_password();  
echo '<hr/>';  
echo $this->make_password(6);  
echo '<hr/>'; 
  
// 记录结束时间  
// 输出运行总时间  
$time_end =  $this->getmicrotime();  
$time = $time_end - $time_start;  
echo "执行时间 $time seconds";

  }

function create_password($pw_length = 8)  
{  
    $randpwd = '';  
    for ($i = 0; $i < $pw_length; $i++)  
    {  
        $randpwd .= chr(mt_rand(33, 126));  
    }  
    return $randpwd;  
}  
// 调用该函数,传递长度参数$pw_length = 6  
 
  
function generate_password( $length = 8 )  
{  
    // 密码字符集,可任意添加你需要的字符  
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_[]{}<>~`+=,.;:/?|';  
  
    $password = '';  
    for ( $i = 0; $i < $length; $i++ )  
    {  
        // 这里提供两种字符获取方式  
        // 第一种是使用 substr 截取$chars中的任意一位字符;  
        // 第二种是取字符数组 $chars 的任意元素  
        // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);  
        $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];  
    }  
  
    return $password;  
}  
  

  
  
function make_password( $length = 8 )  
{  
    // 密码字符集,可任意添加你需要的字符  
    $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', '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',  
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!',  
    '@','#', '$', '%', '^', '&', '*', '(', ')', '-', '_',  
    '[', ']', '{', '}', '<', '>', '~', '`', '+', '=', ',',  
    '.', ';', ':', '/', '?', '|');  
  
    // 在 $chars 中随机取 $length 个数组元素键名  
    $keys = array_rand($chars, $length);  
    $password = '';  
    for($i = 0; $i < $length; $i++)  
    {  
        // 将 $length 个数组元素连接成字符串  
        $password .= $chars[$keys[$i]];  
    }  
    return $password;  
}  
  
 
  
//记录时间  
function getmicrotime()  
{  
    list($usec, $sec) = explode(" ",microtime());  
    return ((float)$usec + (float)$sec);  
}  
  
    
}


    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值