设为首页收藏本站

91ROOT

 找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
热搜: udp
查看: 1010|回复: 2

[PHP] 密码变量pwdHash的生成算法 [复制链接]

Rank: 9Rank: 9Rank: 9

发表于 2010-2-1 17:35:09 |显示全部楼层
很多弟兄对备案系统中pwdHash变量的生成算法不是太明白,发一段PHP的简单例程
  1. <?php
  2. //---------------------------------------------------------------
  3. //        密码变量pwdHash的生成算法 PHP版本 V0.1
  4. //        (c) 2010 Smallthing
  5. //        website: http://www.91root.com/
  6. //        转载请勿删除版权谢谢大家 ---分享互联网---
  7. //---------------------------------------------------------------
  8. function hex2bin($hexdata)//将16进制数串转换为二进制数据的函数
  9.         {
  10.         $bindata="";
  11.         for ($i=0;$i<strlen($hexdata);$i+=2) {
  12.             $bindata.=chr(hexdec(substr($hexdata,$i,2)));
  13.         }
  14.         return $bindata;
  15.     }

  16. function randString($length)//获取随机大小写数字字符串的函数
  17.         {
  18.    $newstring="";
  19.    if($length>0) {
  20.        while(strlen($newstring)<$length) {
  21.            $randnum = mt_rand(0,61);
  22.            if ($randnum < 10) {
  23.                $newstring.=chr($randnum+48);
  24.            } elseif ($randnum < 36) {
  25.                $newstring.=chr($randnum+55);
  26.            } else {
  27.                $newstring.=chr($randnum+61);
  28.            }
  29.        }
  30.    }
  31.    return $newstring;
  32. }

  33. $randVal = randString(20); //获取20位随机字符串
  34. //echo $randVal;//显示$randVal,调试使用
  35. $pwd="123";//管局提供的密码
  36. $pwdHash=base64_encode(hex2bin(md5($pwd.$randVal)));//生成变量pwdHash的最终Base64哈希值
  37. //echo $pwdHash;//显示$pwdHash,调试使用
  38. ?>
复制代码

Rank: 1

发表于 2010-3-18 12:49:39 |显示全部楼层
不好意思,版主,我……不会PHP,我是JAVA与C++,但大概能看得懂,可否给出对一个串Hash后的结果值,如123,Hash后是多少?以方便我用JAVA调试,谢谢

使用道具 举报

Rank: 5Rank: 5

发表于 2010-3-18 17:59:50 |显示全部楼层
这个我已经做了一套在线版的,一会联系一下传上去好了

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

手机版|Archiver|91root技术区 ( 皖ICP备09028067号 )  

GMT+8, 2012-2-6 22:18 , Processed in 0.048082 second(s), 17 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部