检查字符串是否是MD5哈希 [英] Check if string is an MD5 Hash
本文介绍了检查字符串是否是MD5哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在存储密码之前,我不小心停止了散列密码,所以现在我的数据库混合了MD5密码和未经过哈希的密码。
I accidentally stopped hashing passwords before they were stored, so now my database has a mix of MD5 Passwords and unhashed passwords.
我想循环并散列那些不是MD5的。是否有可能检查一个字符串是否是一个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?
推荐答案
您可以使用以下函数进行检查:
You can check using the following function:
function isValidMd5($md5 ='')
{
return preg_match('/^[a-f0-9]{32}$/', $md5);
}
echo isValidMd5('5d41402abc4b2a76b9719d911017c592');
MD5(消息摘要算法)散列通常用文本格式为32位十六进制数字。
The MD5 (Message-digest algorithm) Hash is typically expressed in text format as a 32 digit hexadecimal number.
这个函数检查:
This function checks that:
- 它只包含字母和数字(az,0-9)。
- 长度为32个字符。
这篇关于检查字符串是否是MD5哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文