Question

When looking through my PHP code, I found that the area of my code where I performed a multiple iteration hash of my code was causing problems, not allowing the page to be loaded (when I tried to load register.php, it would simply load a white blank page). I can't seem to find the error in my code though. Any help would be greatly appreciated!

function RandomString($length) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}
$code = RandomString(25);
mail($email, "Your code for the Assassin game.", "Your code is: $code");
$salt = RandomString(8);
$hashedcode = "";
for($i=0;$i<5;i++){
    $hashedcode = sha1($hashedcode.$code.$salt);
}
Was it helpful?

Solution

Your last loop, which seems pointless anyway since it's just overwriting $hashedcode, will never end because you're incrementing a constant i instead of the $i var, and so $i remains 0, which is forever less than 5, yielding that condition infinitely true:

for($i=0;$i<5;i++){
    $hashedcode = sha1($hashedcode.$code.$salt);
}

should be

for($i=0;$i<5;$i++){
    $hashedcode = sha1($hashedcode.$code.$salt);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top