Alright, so I've added quite a bit of "functionality". Users can supply a demo password and as many hashes as is supported by PHP. I dynamically generated the jQuery that dynamically generates the hash selectors by using hash_algos() to pull all the available hashes supported by my servers current version of PHP, 5.2.17.
Upon submission, it verifies that there is at least one hash and a demo password, though I'll remove the need for a demo password (make it optional) after I've fixed my one bug (that I'm aware of). There is already code in place to retain the password in case the form is submitted without adding a hash. I'll add the same for the dynamically generated hash selectors, after I get my bug fixed.
The output works fine, with one exception. I can't get the bloody thing to run the letter/number hashing of the demo password, and I can't figure out why. I'll try to keep the code I put up here for this simple by only putting up where there's a problem.
Everything in my code works up to an if...then...else statement I have for generating the demo password hash (eval() just didn't want to work, also because of the letter/number hashing). Here's the statement:
Code:
$hashName = strtolower(str_replace(",", "", str_replace(" ", "", $hashList[$j][0])));
if($hashName == 'letterhashing')
{
$hashed = strtr($hashed, $letters);
}
else if($hashName == 'numberhashing')
{
$hashed = strtr($hashed, $numbers);
}
else if($hashName == 'md5')
{
$hashed = md5($hashed);
}
else if($hashName == 'sha1')
{
$hashed = sha1($hashed);
}
else if($hashName == 'crc32')
{
$hashed = hash('crc32', $hashed);
}
else
{
$hashed = $hashName($hashed);
}
Basically, for the hashes that have a function by default in PHP, I've just done a straight hash. For the other supported hashes that don't have their own function, I've dynamically generated functions for each one and they are then called. In the case of the letter/number hashing, I just ran the strtr() instead of bothering with anything else. Now, I've verified by added prompts, alerts, echos, etc. that the $hashName is 'letterhashing' after applying the formatting, but it will not acknowledge in the comparison. All the other comparisons work, md5, sha1, and crc32, but letterhashing and numberhashing won't work. I've even copied the output of the prompts directly into the code to ensure it matches the output, but nothing changed.
I know the issue is with the comparisons because the strtr() runs if I put it outside the if statement, and the prompts I put direct before the if do not pop when put directly after the if.
I've tried substituting for strcasecmp() and redeclaring the $hashName variable immediately before the if, but to no avail.
There appears to be no shortage of people have similar issues, but every case I've looked at (well over 50) was a bloody typo somewhere, or they just weren't doing it right. I know my code should work, but it's not.
Here's a Ideone that shows that the code works when I rip it out of everything else:
Ideone.com - HFxZFs - Online PHP Interpreter & Debugging Tool
Any ideas?
Edit:
Oh, the link to the version of the generator I'm working on is:
http://zrift.com/Login Hash/index2.php