Compare the token from an email to a user's token for account activation -


i need send user email link can click on activate account. here code:

//add method users controller, sends email when new user added   public function add()     {     $user = $this->users->newentity();     if ($this->request->is('post')) {         $user = $this->users->patchentity($user, $this->request->data);           $newauthtoken = bin2hex(openssl_random_pseudo_bytes(16));          $user['authtoken'] = $newauthtoken;         $user['activated'] = null;          if ($this->users->save($user)) {             $this->flash->success(__('the user has been saved.'));              $ms='click on link below complete registration ';             $ms.='urlhere.com/users/activate/t:'.$newauthtoken.'';             $ms=wordwrap($ms,70);               $email = new email('default');             $email->viewvars();             $email->template('default')->viewvars(array('user' => $user))             ->emailformat('html')             ->to($user['email'])             ->from('admin@example.com')             ->subject('hello ' . $user['email'])             ->send($ms);               return $this->redirect(['action' => 'index']);         } else {             $this->flash->error(__('the user not saved. please, try again.'));         }     }      $groups = $this->users->groups->find('list', ['limit' => 200]);     $answers = $this->users->answers->find('list', ['limit' => 200]);     $courses = $this->users->courses->find('list', ['limit' => 200]);     $this->set(compact('user', 'groups', 'answers', 'courses'));     $this->set('_serialize', ['user']); } 

here function should compare email token(from link) tokens in users table , set timestamp activated if match:

//activate function users controller, should set timestamp activated public function activate($id = null) { if (!empty($this->passedargs['t'])){     $tokenhash = $this->passedargs['t'];     $results = $this->user->find('first', array('conditions' => array('authtoken' => $tokenhash)));           if($results['authtoken']==$tokenhash) {         $this->user->id = $results['id'];         $this->user->savefield('activated', current_datetime());         $this->flash->success(__('the user has been saved.'));         return $this->redirect(['action' => 'index']);         exit;     } else {         $this->flash->error('tokens not match');         return $this->redirect(['action' => 'index']);      } } } 

any ideas why isn't working?


Comments