首页 > 技术文章 > tocke - 加密

nyfz 2018-08-04 17:00 原文

//获取32位随机字符串
$randTocke = getRandChar($length);
//当前脚本运行时间, 单位为十万分之一毫秒
$timestamp = $_SERVER['REQUEST_TIME_FLOAT'];
//盐(自定义字符串,加密用)
$sale = config('secure.token_salt');
//md5加密
md5($randTocke.$timestamp.$sale);

 

function getRandChar($length){
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol)-1;

for($i=0;$i<$length;$i++){
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}

return $str;
}

推荐阅读