2012-05-17 2 views
0

간단한 로그인/등록 페이지를 작성했습니다. 등록 페이지는 데이터베이스에 정보를 전달하지만,이 정보로 로그인을 시도하면 잘못된 비밀번호/사용자 이름이 페이지에 계속 올라갑니다. 나는 Andrew Perkins 튜토리얼 (cakephp 2.0 auth)을 따라 왔고 그의 코드는 그의 코드와 동일하다. 내 모든 데이터가페이지가 로그인 정보를 허용하지 않습니다.

-users 컨트롤러

<?php 

class UsersController extends AppController{ 

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

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

    public function isAuthorize($user){ 
     if(in_array($this->action, array('edit',delete))){ 
     if($user['id'] !=$this->request->params['pass'][0]){ 
      return false; 
     } 
     } 
     return true; 
    } 
    public function login(){ 
     if($this->request->is('post')){ 
      if($this->Auth->login()){ 
       $this->redirect($this->Auth->redirect()); 
      }else{ 
       $this->Session->setFlash('Your username/password was incorrect'); 

      } 

     } 
    } 

    public function logout(){ 
    $this->redirect($this->Auth->logout()); 
    } 

    function add(){ 
     $this->set('title_for_layout', 'Individual Registration'); 
     $this->set('stylesheet_used', 'style'); 
     $this->set('image_used', 'eBOXLogo.jpg'); 
if($this->request->is('post')){ 
{ $this->User->create(); 
if ($this->User->save($this->request->data)) 
{ 
    $this->Session->setFlash('The user has been saved'); 

} 
    else { $this->Session->setFlash('The user could not be saved. Please, try again.'); } 
    } 

    } 

    } 
} 

-app 컨트롤러

<?php 

App::uses('Controller', 'Controller'); 

class AppController extends Controller { 
    public $components = array(
     'Session', 
     'Auth'=>array(
      'longinRedirect'=>array('controller'=>'users', 'action'=>'index'), 
      'longoutRedirect'=>array('controller'=>'users', 'action'=>'index'), 
      'authError'=>"You can't access this page", 
      'authorize'=>array('Controller') 
     ) 
    ); 

    public function isAuthorized($user){ 
     return true; 
    } 

    public function beforeFilter(){ 
    $this->Auth->allow('index','view'); 
    $this->set('logged_in', $this->Auth->loggedIn()); 
    $this->set('current_user',$this->Auth->user()); 

    } 


} 

- 사용자 모듈

<?php 
class User extends AppModel { 
    public $name = 'User'; 
    public $displayField = 'name'; 

    public $validate = array(
     'name'=>array(
      'Please enter your name.'=>array(
       'rule'=>'notEmpty', 
       'message'=>'Please enter your name.' 
      ) 
     ), 
     'username'=>array(
      'The username must be between 5 and 15 characters.'=>array(
       'rule'=>array('between', 5, 15), 
       'message'=>'The username must be between 5 and 15 characters.' 
      ), 
      'That username has already been taken'=>array(
       'rule'=>'isUnique', 
       'message'=>'That username has already been taken.' 
      ) 
     ), 
     'email'=>array(
      'Valid email'=>array(
       'rule'=>array('email'), 
       'message'=>'Please enter a valid email address' 
      ) 
     ), 
     'password'=>array(
      'Not empty'=>array(
       'rule'=>'notEmpty', 
       'message'=>'Please enter your password' 
      ), 
      'Match passwords'=>array(
       'rule'=>'matchPasswords', 
       'message'=>'Your passwords do not match' 
      ) 
     ), 
     'password_confirmation'=>array(
      'Not empty'=>array(
       'rule'=>'notEmpty', 
       'message'=>'Please confirm your password' 
      ) 
     ) 
    ); 

    public function matchPasswords($data) { 
     if ($data['password'] == $this->data['User']['password_confirmation']) { 
      return true; 
     } 
     $this->invalidate('password_confirmation', 'Your passwords do not match'); 
     return false; 
    } 

    public function beforeSave() { 
     if (isset($this->data['User']['password'])) { 
      $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); 
     } 
     return true; 
    } 
} 
?> 

를 저장 위치

아니야 자,가요 데이터베이스 사용자입니다 로그인보기

<h2>Login</h2> 
<?php 
echo $this->Form->create(); 
echo $this->Form->input('username'); 
echo $this->Form->input('password'); 
echo $this->Form->end('Login'); 
?> 
+0

내가 코드를 검토했다 .. u는 UR 데이터베이스에 암호를 삽입하는 방법을 확인하는 암호화 형식 ,, 어떻게 당신이 .. 로그인에 대한 쿼리를 발사 또는 케이크 책에서 인증을 읽으려고 ... –

+0

더 구체적으로 말씀 드리면, 그 암호는 데이터베이스에 해시됩니다. – user1393064

답변

0

, 웹 사이트가 40 문자 긴 문자열을 전송 한 시도 데이터베이스에 올바르게 저장되지 않습니다.

사용 debugkit 플러그인과는

0

당신이 있었다 추가 기능의 추가와 후크는,이 데이터베이스가 20 문자 긴 문자열로 저장 한 하나

if ($this->request->is('post')) { 

    $this->User->create(); 

    if ($this->User->save($this->request->data)) { 
     $this->Session->setFlash('The user has been saved'); 
    } else { 
     $this->Session->setFlash('The user could not be saved. Please, try again.'); 
    } 
} 
+0

건배, 로그인하는 데 도움이되는 팁? – user1393064

+0

데이터베이스가 20 자 긴 문자열로 저장 중이며 웹 사이트에서 40 자 긴 문자열을 보내고 데이터베이스에 올바르게 저장하지 않습니다. 디버그 플러그인을 사용하여 효과가있었습니다. – user1393064

관련 문제