当我尝试在SQL中进行哈希时获取错误

时间:2012-03-28 17:23:51

标签: sql md5

我想将数据库中明文的字符串与用MD5()进行哈希处理的字符串进行比较。我试过这样的事情:

SELECT member_email, is_validated FROM members
WHERE CONVERT(VARCHAR(32), HASHBYTES('MD5', 'member_email'), 2) = '".$_GET['vy']."'
AND is_validated = '0'

但我得到了You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(32), HASHBYTES('MD5', 'member_email'), 2) = '' AND is_valida' at line 2。如果我删除'in 'member_email',那么HASHBYTES('MD5', member_email)我将收到相同的错误消息。怎么了?我是否必须将MD5哈希值放在数据库中,以便将其与$_GET['vy']中的相同MD5哈希进行比较?

提前致谢!

1 个答案:

答案 0 :(得分:0)

MySQL有HASHBYTES()吗? http://dev.mysql.com/doc/refman/5.6/en/encryption-functions.html

你试过了吗?

SELECT member_email, is_validated FROM members
WHERE CONVERT(VARCHAR(32), MD5(member_email), 2) = '".$_GET['vy']."'
AND is_validated = '0'