很多弟兄对备案系统中pwdHash变量的生成算法不是太明白,发一段PHP的简单例程- <?php
- //---------------------------------------------------------------
- // 密码变量pwdHash的生成算法 PHP版本 V0.1
- // (c) 2010 Smallthing
- // website: http://www.91root.com/
- // 转载请勿删除版权谢谢大家 ---分享互联网---
- //---------------------------------------------------------------
- function hex2bin($hexdata)//将16进制数串转换为二进制数据的函数
- {
- $bindata="";
- for ($i=0;$i<strlen($hexdata);$i+=2) {
- $bindata.=chr(hexdec(substr($hexdata,$i,2)));
- }
- return $bindata;
- }
- function randString($length)//获取随机大小写数字字符串的函数
- {
- $newstring="";
- if($length>0) {
- while(strlen($newstring)<$length) {
- $randnum = mt_rand(0,61);
- if ($randnum < 10) {
- $newstring.=chr($randnum+48);
- } elseif ($randnum < 36) {
- $newstring.=chr($randnum+55);
- } else {
- $newstring.=chr($randnum+61);
- }
- }
- }
- return $newstring;
- }
- $randVal = randString(20); //获取20位随机字符串
- //echo $randVal;//显示$randVal,调试使用
- $pwd="123";//管局提供的密码
- $pwdHash=base64_encode(hex2bin(md5($pwd.$randVal)));//生成变量pwdHash的最终Base64哈希值
- //echo $pwdHash;//显示$pwdHash,调试使用
- ?>
复制代码 |