我发送的链接如下
users/reset?token=0272dcff7439023e082204ac9fe9b96b
token = user_email
在获取令牌后的控制器中,我试图将此字符串与数据库电子邮件字段匹配。
我已尝试过以下代码,但此处查询无法正常工作
public function search(){
if($this->request->is(['post','get'])){
$email = $this->request->query('token');
$query = $this->Users->find('all', [
'conditions' => [md5('Users.email') =>$email],
'fields' => ['email','username']
]);
}
如何将此md5或base_64字符串与蛋糕查询中的电子邮件字段匹配?
答案 0 :(得分:0)
如果您的令牌存储为$token = md5($email);
然后你只需要下面的代码来检索记录
public function search(){
if($this->request->is(['post','get'])){
$email = $this->request->query('token');
$query = $this->Users->find('all', [
'conditions' => ['Users.email' =>$email], //hope you store email id as email not in md5
'fields' => ['Users.email','Users.username']
]);
}
因为您无法设置字段md5。
希望它会对你有所帮助。
由于
答案 1 :(得分:0)
当我刚刚更改我的代码时它正在工作
'conditions' => [md5('Users.email') =>$email],
到
'conditions' => ['md5(Users.email)' =>$email],