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:
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