Home > php教程 > php手册 > 今天和大家探讨一个很重要的问题密码安全

今天和大家探讨一个很重要的问题密码安全

WBOY
Release: 2016-06-21 09:14:07
Original
1171 people have browsed it

安全|问题

PHP代码:--------------------------------------------------------------------------------
$sRand = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$length = strlen($sRand);

if (!($dir = @opendir("/dic"))) {
mkdir ("dic", 0777);
}

for ($q=0; $q if ($q > 25 && $q $op = 'cap';
} else {
$op = '';
}
$fp = fopen("./dic/".$op.$sRand[$q].".txt", "w");
$crack = $sRand[$q];
fputs($fp, $crack."|".md5($crack)."\n");
for ($m=0; $m $crack = $sRand[$q].$sRand[$m];
fputs($fp, $crack."|".md5($crack)."\n");
for ($l=0; $l $crack = $sRand[$q].$sRand[$m].$sRand[$l];
fputs($fp, $crack."|".md5($crack)."\n");
for ($o=0; $o $crack = $sRand[$q].$sRand[$m].$sRand[$l].$sRand[$o];
fputs($fp, $crack."|".md5($crack)."\n");
}
}
}
fclose($fp);
}

--------------------------------------------------------------------------------


需要注意地是,这只是一个例子,为了简单期间,我们锁定密码字元为26个小写字母,26个大写字母,10个数字(相信应该适合大多数密码了,不知哪位BT朋友加标点符号呢?呵呵……),而我们只测试四位以内地密码,密码位数增多时原理相同,只是破解可能性大大降低,这个一会儿再讲。

这样,就再dic目录下产生了一系列字典文件。
现在,让我们来做一个MD5的随机密码:

PHP代码:--------------------------------------------------------------------------------
$afcontent = file("./dic/".$op.$sRand[$s].".txt", "r");
foreach($afcontent as $sdics) {
$adics = explode("|", $sdics);
if (substr($adics[1], 0, 32) == $md5_pwd) {
echo "破解密码为:".$adics[0]."
";
$mtime = explode(' ', microtime());
$endtime = $mtime[1] + $mtime[0];
echo "总耗时:".round($endtime - $starttime, 6)."秒

";
echo "继续测试";
exit();
}
}

for ($s=0; $s if ($s >25 && $s $op = 'cap';
} else {
$op = '';
}
$afcontent = file("./dic/".$op.$sRand[$s].".txt", "r");
foreach($afcontent as $sdics) {
if (md5($sdics) == $md5_pwd) {
echo "破解密码为:".$sdics;
exit();
}
}
}

--------------------------------------------------------------------------------


在程序中,你再加上检测运行时间的代码,就可以知道破解一个62字元四位长度的MD5密码需要多长时间了。。。
没测之前,大家先估计一下呢?


还有,现在默认要产生大概537M~~
且需花费15分钟左右生成字典(在我PIII733 256M 内存上)





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template