Check if string is an MD5 Hash

前端 未结 2 1380
Happy的楠姐
Happy的楠姐 2020-12-24 00:58

I accidentally stopped hashing passwords before they were stored, so now my database has a mix of MD5 Passwords and unhashed passwords.

I want to loop through and ha

相关标签:
2条回答
  • 2020-12-24 01:26

    You can check using the following function:

    function isValidMd5($md5 ='')
    {
        return preg_match('/^[a-f0-9]{32}$/', $md5);
    }
    
    echo isValidMd5('5d41402abc4b2a76b9719d911017c592');
    

    The MD5 (Message-digest algorithm) Hash is typically expressed in text format as a 32 digit hexadecimal number.

    This function checks that:

    1. It contains only letters and digits (a-f, 0-9).
    2. It's 32 characters long.
    0 讨论(0)
  • 2020-12-24 01:32

    Maybe a bit faster one:

    function isValidMd5($md5 ='') {
      return strlen($md5) == 32 && ctype_xdigit($md5);
    }
    
    0 讨论(0)
提交回复
热议问题