我正在玩关于创建一个包含任何密码组合的纯文本和哈希值的数据库,但是当它们被添加到数据库中时,我最终会得到许多重复项,然后再继续下一个组合......关于为什么的任何想法以及如何阻止它?
<?php
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$numberof=0;
$alphabet = 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");
for($i=0; $i<count($alphabet); $i++){
for($j=0; $j<count($alphabet); $j++){
for($k=0; $k<count($alphabet); $k++){
for($l=0; $l<count($alphabet); $l++){
$final = $alphabet[$i].$alphabet[$j].$alphabet[$k];
$hash = md5($final);
mysqli_query($con,"INSERT INTO hashes (plain, hash) VALUES ('$final', '$hash')");
}
}
}
}
echo $numberof;
?>