简体   繁体   English

使用ID的md5版本查询字段

[英]Query a field wiith md5 version of id

EDITED TO ADD MORE INFO 编辑以添加更多信息

I need to use mysql's md5 function to select an item using it's id field ( uid ). 我需要使用mysql的md5函数通过其id字段( uid )选择一个项目。 I have a separate database from my users called recover_db that has an md5 hashed value of the user id in it and a time stamp. 我有一个与用户分开的数据库,名为recover_db ,该数据库中具有用户ID的md5哈希值和时间戳。

Currently the users visit a link like this: 当前,用户访问这样的链接:

recover-MD%HASHEDUSERID.html

Then the system takes that MD%HASHEDUSERID from the url and checks if it exists in the recover_db and if it does it lets them recover the account. 然后,系统从URL中获取该MD%HASHEDUSERID ,并检查它是否存在于recover_db ,如果存在,则允许他们恢复该帐户。 There's some other stuff for security and whatnot but I do not store the user id in the recover_db , just the MD5 value of it. 还有其他一些安全性方面的内容,但是我没有将用户ID存储在recover_db ,只是存储了它的MD5值。 I use the following to do that: 我使用以下方法来做到这一点:

md5(90*13/12*56+$id)

Now I need to check the users database and get the REAL account id using the md5 value I have saved. 现在,我需要检查用户数据库并使用保存的md5值获取REAL帐户ID。 I was using the following query to do this: 我正在使用以下查询来执行此操作:

$query = "SELECT uid FROM users where md5(90*13/12*56+uid)='".$md5accID."'";

Unfortunately this is returning no results. 不幸的是,这没有任何结果。 Is there any way to get the real user id from the users database using the md5 version of it from the recover_db ? 有什么办法可以使用来自recover_db的md5版本从users数据库中获取真实的用户ID? I want to avoid storing the user id in the recover_db if I can. 如果可以的话,我想避免将用户ID存储在recover_db中。

Save the original user ID in a field origuid together with the hash ( hasheduid ) in the recovery database. 将原始用户ID与哈希( hasheduid )一起hasheduid在恢复数据库中的字段origuid中。 Then do 然后做

$query = "SELECT origuid FROM users where hasheduid='".$md5accID."'";

to retrieve the original user ID. 检索原始用户ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM