2014-03-01 20 views
1

我一直在寻找通过多年和再次即时通讯棒,代码没有回声出来时确定,当我把正确的密码在用户匹配数据库中的密码和即时通讯难倒。在下面的代码回声OK不工作?

其他一切wroks罚款,如果林不知道,香港专业教育学院错过了什么傻掉了我的概率有哑巴:)

PHP所以道歉:

class User { 
    private $_db, $data; 

    public function __construct($user = null) { 
     $this->_db = DB::getInstance(); 
    } 

    public function create($fields = array()) { 
     if(!$this->_db->insert('users', $fields)) { 
      throw new Exception('There was a problem registering'); 
     } 
    } 

    public function find($user = null) { 
     if($user) { 
      $field = (is_numeric($user)) ? 'id' : 'username'; 
      $data = $this->_db->get('users', array($field, '=', $user)); 

      if($data->count()) { 
       $this->_data = $data->first(); 
       return true; 
      } 
     } 
     return false; 
    } 

    public function login($username = null, $password = null) { 
     $user = $this->find($username); 

     if($user) { 
      if($this->data()->password === Hash::make($password, $this->data()->salt)) { 
       echo 'ok'; 
      } 
     } 

     return false; 
    } 

    private function data() { 
     return $this->_data; 
    } 
} 
+0

你有没有检查你的PHP日志? –

+0

看来你要么使用不同的散列函数来注册和登录,要么你的凭证是错误的。 – Kelm

回答

1

在您login(),你必须重写像这样..

public function login($username = null, $password = null) { 

     $user = $this->find($username); 


     if($user) { 
      if($this->data()->password === Hash::make($password, $this->data()->salt)) { 
       //echo 'ok'; 
       return true; 
      } 

     } 
     else { return false; } 
    } 

注释掉echo并且从那里返回true。所以,你会从你的实例中callingyour功能像

if($someinst->find('someuser')) 
     { 
     echo "User Found"; 
     } 
else { echo "Not Found"; } 
1

尝试使用此方法吸引您的问题:

public function login($username = null, $password = null) 
{ 
    $user = $this->find($username); 

    if($user) { 
     if($this->data()->password === Hash::make($password, $this->data()->salt)) { 
      echo 'User and password Ok!';    
     } else { 
      echo 'User and password do not match'; // Handle it 
     } 
    } else { 
     echo 'User not found'; // Handle it 
    } 
    return false; 
} 

而且,在第一看来,这可能是问题:

$this->data()->password 

也许你应该使用类似的东西:

if($user->password === Hash::make($password ...