2016-08-13 1 views
0

Je veux créer le custompasswordhasher pour mon projet cakephp. la version de cakephp est 2.5. Je suivre le livre et CakePHP cuire créer la classe personnalisée suivante dans le contrôleur de répertoire/auth/CustomPasswordHasher.phpcakephp create custompassword hasher erreur interne du serveur

App::uses('AbstractPasswordHasher', 'Controller/Component/Auth'); 

class CustomPasswordHasher extends AbstractPasswordHasher { 
    public function hash($password) { 
     $hasher = md5(Configure::read('Security.salt') . $password . Configure::read('Security.cipherSeed')); 
     return $hasher; 
    } 

    public function check($password, $hashedPassword) { 
     //debug('PHPassHasher'); die('Using custom hasher'); //<--THIS NEVER HAPPENS! 
     $password = md5(Configure::read('Security.salt') . $password . Configure::read('Security.cipherSeed')); 
     echo $password."==".$hashedPassword;exit; 
     return password_verify($password, $hashedPassword); 
    } 
} 

et voici ma fonction de connexion dans le contrôleur

public function admin_login() { 
    if ($this->Auth->loggedIn()) { 
     return $this->redirect($this->Auth->redirect()); 
    } 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirect()); 
     } else { 
      $this->Session->setFlash('Username or password is incorrect', 'error'); 
     } 
    } 
} 

et appController.php Je config fonction

public function beforeFilter() { 

     if ($this->request->prefix == 'admin') { 
      $this->layout = 'admin'; 
      AuthComponent::$sessionKey = 'Auth.User'; 
      $this->Auth->loginAction = array('controller' => 'administrators', 'action' => 'login'); 
      $this->Auth->loginRedirect = array('controller' => 'administrators', 'action' => 'dashboard'); 
      $this->Auth->logoutRedirect = array('controller' => 'administrators', 'action' => 'login'); 
      $this->Auth->authenticate = array(
       'all' => array(
        'scope' => array(
         'User.is_active' => 1 
        ) 
       ), 
       'Form' => array(
        'userModel' => 'User', 
        'passwordHasher' => array(
         'className' => 'Auth/CustomPasswordHasher' 
        ) 
       ) 
      ); 
      $this->Auth->allow('login'); 
     } else { 
      /* do another stuff for user authentication */ 
     } 
    } 

Et voici mon formulaire de connexion.

<div class="login-box"> 
    <div class="login-logo">Admin Login</div> 
    <div class="login-box-body"> 
     <p class="login-box-msg">Sign in to start your session</p> 
     <?php echo $this->Session->flash(); ?> 
     <?php echo $this->Form->create(); ?> 
      <div class="form-group has-feedback"> 
       <?php 
        echo $this->Form->input('User.username', 
         array(
          'label'   => false, 
          'class'   => 'form-control', 
          'placeholder' => 'Username', 
          'autocomplete' => 'off', 
          'autofocus'  => true, 
          'value'   => @$username 
         ) 
        ); 
       ?> 
       <span class="glyphicon glyphicon-envelope form-control-feedback"></span> 
      </div> 
      <div class="form-group has-feedback"> 
       <?php 
        echo $this->Form->input('User.password', 
         array(
          'type'   => 'password', 
          'label'   => false, 
          'class'   => 'form-control', 
          'placeholder' => 'Password', 
          'value'   => @$password 
         ) 
        ); 
       ?> 
       <span class="glyphicon glyphicon-lock form-control-feedback"></span> 
      </div> 
      <div class="row"> 
       <div class="col-xs-8">  
        <div class="checkbox icheck "> 
         <label> 
         <input type="checkbox" name="data[Admin][remember_me]"> Remember Me </label> 
        </div>       
       </div> 
       <div class="col-xs-4"> 
        <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button> 
       </div> 
      </div> 
     <?php echo $this->Form->end(); ?> 
     <a href="#forgotpassword" data-toggle="modal" data-target="#forgot_password_modal1">I forgot my password</a><br> 
    </div> 
</div> 

Comment chaque formulaire de soumission. Je suis la pile trace

enter image description here

Donc tout le monde peut vous me aider?

+0

Eh bien, quel est le message d'erreur réel pour la ligne 138 dans passwordHasher? – Challe

+0

Eh bien, j'ai vu la cause maintenant. parce que j'appelle mauvais className dans mon contrôleur. il devrait être "Custom" et non "CustompasswordHasher". Le gâteau va automatiquement ajouter cela. –

Répondre

0

J'appelle mauvais className dans mon contrôleur. il devrait être "Custom" et non "CustompasswordHasher". Le gâteau va automatiquement ajouter cela.