Two same hash function with same values return different outputs

True. If the OP has been instructed by their boss to do this kind of exercise then they are in a pickle. However, I don’t think that’s the case. A lot of professional jobs even startups have senior developers. They most certainly wouldn’t be telling junior developers to be doing this kind of exercise. It would be a strange thing to do if it was asked by a senior developer. So, I don’t think it’s the case of professionalism.

What we should really ask is what is this exercise for. Is it for school, work, or for fun.

1 Like

better var_dump the value. this comes with the string length included.

1 Like

that’s the perfect reason to talk about better concepts, instead of just posting a technical possiblity, imho.

1 Like

I agree, it just seemed in some parts to just be criticising the OP for not wanting to do it the correct way, far beyond the point where that way had been pointed out.

Yes, and does it even have anything to do with storing passwords for a live system? For all we know, the OP is maybe trying to show why it shouldn’t be done that way.

I guess that depends on whether the senior developer is senior through experience and knowledge, or senior through owning the business or similar. I’d like to think the latter are a dying breed.

<?php
$passwordFile = fopen("passwords.txt", "r") or die("Unable to open file!");
$hashFile = fopen("hash.txt","w") or die("death to all heretics!");
while($password = fgets($passwordFile))
{
    $password = trim($password);
    if ($password) { // guard against empty lines
        $hash = md5(sha1($password));
        //echo $hash . "\n";
        fputs($hashFile,$hash . "\n");
    }
}
fclose($hashFile);
fclose($passwordFile);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.