2011-12-10 80 views
0

私はログイン作業をしようとしています...しかし、私がmd5を持っていた(addを使って)登録すると、$ this-> Auth-> passwordに変更されました。その後、私はその行なしで試してみました..まあ、初めてログインしても問題ありませんでしたが、何らかの理由でログイン時に再びハッシュを変更してしまいました。データベースを修正する方法はわかりません。パスワードハッシングが正しく動作しない

<?php 
class UsersController extends AppController { 

    var $uses = array("User"); 
    var $components = array('Auth', 'Session'); 


    function index() 
    { 
     $this->set('users', $this->User->find('all')); 
     $this->layout = 'master_layout'; 
    } 

    function beforeFilter() { 
     $this->Auth->allow('add'); 
     } 

     function add() { 

      if (!empty($this->data)) { 
      //pass is hashed already 
      //->data['User']['password'] = $this->Auth->password($this->data['User']['password']); 
      if ($this->User->save($this->data)) { 
       $this->Session->setFlash('Your were registered!.'); 
           $this->redirect(array('action' => 'index')); 
      } 
      } 

     $this->layout = 'master_layout'; 
     } 

    //IF THE DATABASE IS SET UP CORRECTLY CAKE AUTHENTICATES AUTOMATICALLY NO 
    //LOGIC IS NEEDED FOR LOGIN http://book.cakephp.org/view/1250/Authentication 
    function login() { 
     $this->layout = 'master_layout'; 
    } 

    function logout() { 

    $this->redirect($this->Auth->logout()); 

    } 

} 
?> 

VIEW

<?php 
echo $this->Session->flash('auth'); 
echo $this->Form->create('User'); 
echo $this->Form->input('username'); 
echo $this->Form->input('password'); 
echo $this->Form->end('Login'); 
?> 

答えて

1

あなたがフォーム上のフィールド名としてパスワードを使用するはずの。 この方法でも空の文字列が保存され、すでに保存されている文字列が混乱します。あなたのbeforeSaveメソッドによっては空の文字列がハッシュとして保存されることさえあるかもしれません(実際には空のパスワードを隠す)。

http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/何混乱

+0

を参照してください.... – ThiefMaster

+0

あなたは何を意味するのですか? – mark

+0

これは前にuser_passwordを持っていました。 – user710502

関連する問題