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.

$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";
    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! :)

Hi! I'm Mike Dalisay, the co-founder of, a site that helps you build web applications with PHP and JavaScript. Need support? Comment below or contact [email protected]

I'm also passionate about technology and enjoy sharing my experience and learnings online. Connect with me on LinkedIn, Twitter, Facebook, and Instagram.