Gmail / Facebook Style Chat Application
Details Live Demo Download


Posted: Sunday 30th of September 2012

How to check if a string is a valid md5 hash



This tutorial consist of a simple php function that will help you to check if a given string is a valid MD5 hash or not and that means, the given string has to be 32 characters in length and can only consist of letters and numbers.
For instance: To encrypt 123456 with MD5 hash will give you e10adc3949ba59abbe56e057f20f883e
Now test the above hashed with the function to see the result.

Code:

<?php
function MD5_Hashed_is_Valid($md5)
{
      return !empty($md5) && preg_match('/^[a-f0-9]{32}$/', $md5);
}

$MD5_Hashed = "e10adc3949ba59abbe56e057f20f883e";
if(MD5_Hashed_is_Valid($MD5_Hashed))
{
      echo "Your given MD5 Hashed string is valid.";
}
else
{
      echo "Sorry, your given MD5 Hashed string is not valid.";
}
?>




That's it guys...



Comments
0

 

Announcement x
Dear Users and Clients,

This is to inform you that we have recently updated our website generally.

If you experience any problem viewing any part of this website or if you notice that any of our scripts or tutorials are not functioning properly as should be, please click on the Contact Link at the top of this page to report the issue to us.

Our priority is to give you the best of service!


Thank You,
The Vasplus Team

Announcement