PHP 密码生成器 计算生成时间
生活随笔
收集整理的這篇文章主要介紹了
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);
} }
總結
以上是生活随笔為你收集整理的PHP 密码生成器 计算生成时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL 连接
- 下一篇: PHPSTORM插件