问题描述:

I am sending a link like below

users/reset?token=0272dcff7439023e082204ac9fe9b96b

Where token = user_email

In controller after get token, I am trying to match this string with database email field.

I have tried by below code , but here query not working

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']

]);

}

How can I match this md5 or base_64 string with email field in cake query ?

网友答案:

if your token as stored as $token = md5($email);

then you only need below code to retrieve the record

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']
                     ]);

      }

Because you can not set field md5.

Hope it will help you.

Thanks

网友答案:

It's working when I have just change my code

'conditions' => [md5('Users.email') =>$email], 

To

'conditions' => ['md5(Users.email)' =>$email],
相关阅读:
Top