I accidentally stopped hashing passwords before they were stored, so now my database has a mix of MD5 Passwords and unhashed passwords.
我不小心在存储之前停止了散列密码,所以现在我的数据库混合了MD5密码和未散列的密码。
I want to loop through and hash the ones that are not MD5. Is it possible to check if a string is an MD5 hash?
我想循环并散列不是MD5的那些。是否可以检查字符串是否是MD5哈希?
2 个解决方案
#1
83
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.
MD5(消息摘要算法)哈希通常以文本格式表示为32位十六进制数。
This function checks that:
该函数检查:
- It contains only letters and digits (a-z, 0-9).
- 它只包含字母和数字(a-z,0-9)。
- It's 32 characters long.
- 它长32个字符。
#2
25
Maybe a bit faster one:
也许快一点:
function isValidMd5($md5 ='') {
return strlen($md5) == 32 && ctype_xdigit($md5);
}
#1
83
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.
MD5(消息摘要算法)哈希通常以文本格式表示为32位十六进制数。
This function checks that:
该函数检查:
- It contains only letters and digits (a-z, 0-9).
- 它只包含字母和数字(a-z,0-9)。
- It's 32 characters long.
- 它长32个字符。
#2
25
Maybe a bit faster one:
也许快一点:
function isValidMd5($md5 ='') {
return strlen($md5) == 32 && ctype_xdigit($md5);
}