SHA1 Hashing Algorithm

If you’re feeling lazy right now to create your own hashing algorithm (like me haha!), here’s one of best built in hashing algorithm with its new feature in PHP5 – SHA1. It uses US Secure Hash Algorithm 1.
I didn’t hear any successful hacking attempts or tools for sha1 yet. (If you have, please pm me or comment to this post! thanks… ) Unlike for MD5 hashing, there are successful hacking attempts discovered.

HOW TO’s*Comments on codes serves as its explanation


Put the following PHP code in your index.php file.

<?php
$str = 'dalisay'; // we're gonna hash this string

echo sha1( 'dalisay' ); // to be seen on the page

echo nl2br("nn"); // just some line breaks

// in this part, we're just gonna test if sha1 is working in your server
// the random number and digits is the hash code for string 'dalisay'
// the condition for a login system with sha1 passwords goes like this
if ( sha1( $str ) == '49d8801436095c7a0445a3c53c7d31270223069c' ){
    echo "Yes";
}else{
    echo "No";
}
?>

Step 2: Testing. If you end up something like this, sha1 is working fine.

Final output for the codes above

TIPsIf you’re going to use sha1 for passwords to be stored in the database, make the datatype of your password field to BLOB type, just to make it more secure. :)


Thank you for reading! :)

By Mike Dalisay

I'm Mike Dalisay, a pro web developer since 2010. I love web development. Improving our tutorials and source codes makes me happy. Do you want to suggest an edit to our tutorial? Got something to ask about our source codes? Email our team at [email protected]