02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

$obj = new Admin($dbo);<br />

// Load a hash of the word test <strong>and</strong> output it<br />

$hash1 = $obj->testSaltedHash("test");<br />

echo "Hash 1 without a salt:", $hash1, "";<br />

// Pause execution for a second to get a different timestamp<br />

sleep(1);<br />

// Load a second hash of the word test<br />

$hash2 = $obj->testSaltedHash("test");<br />

echo "Hash 2 without a salt:", $hash2, "";<br />

// Pause execution for a second to get a different timestamp<br />

sleep(1);<br />

// Rehash the word test with the existing salt<br />

$hash3 = $obj->testSaltedHash("test", $hash2);<br />

echo "Hash 3 with the salt from hash 2:", $hash3;<br />

?><br />

CHAPTER 6 ■ PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS<br />

■ Note The sleep() function delays execution of a script <strong>by</strong> a given number of seconds, passed as its sole<br />

argument. You can learn more about this function at http://php.net/sleep.<br />

Your results will not be identical because the timestamp hashes used for the salt will differ; however,<br />

your results should look something like this:<br />

Hash 1 without a salt:<br />

518fd85bb85815af85e88b7c43d892238af9a5ca5775807<br />

Hash 2 without a salt:<br />

93b14e3f42ca09cafc1330b592669a5d02e9815bc2f69de<br />

Hash 3 with the salt from hash 2:<br />

93b14e3f42ca09cafc1330b592669a5d02e9815bc2f69de<br />

211

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!