CakePHP $this->Auth->login() false zurück
Ich habe einen Benutzer erstellt, mit der hash der Kuchen .. Aber wenn ich auf log in, sagt 'Invalid username or password'. Aber es ist alles in Ordnung.
Den $this->Auth->login();
immer false zurück...
Crontroller
class MastersController extends AppController{
public function login(){
if ($this->request->is('post')) {
debug($this->Auth->login());
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
}
else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
public function logout(){
$this->redirect($this->Auth->logout());
}}
AppController
class AppController extends Controller {
public $components = array('Session', 'Cookie', 'Auth');
function beforeFilter() {
$this->loadModel('Master');
$this->Auth->userModel = 'Master';
$this->Auth->allow('*');
//Action da tela de login
$this->Auth->loginAction = array(
'masters' => false,
'controller' => 'masters',
'action' => 'login'
);
//Action da tela após o login (com sucesso)
$this->Auth->loginRedirect = array(
'masters' => true,
'controller' => 'masters',
'action' => 'index'
);
//Action para redirecionamento após o logout
$this->Auth->logoutRedirect = array(
'masters' => false,
'controller' => 'pages',
'action' => 'login'
);
$this->Auth->authorize = array('controller');
if (!isset($this->params['masters']) || !$this->params['masters'])
$this->Auth->allow('*','login');
$this->Auth->loginError = __('Usuário e/ou senha incorreto(s)', true);
$this->Auth->authError = __('Você precisa fazer login para acessar esta página', true);
}
public function isAuthorized($masters){
return TRUE;
}}
VIEW-login.ctp
echo 'Formulário de login';
echo $this->Session->flash('auth');
echo $this->Session->flash();
echo $this->Form->create('Master', array('controller'=>'masters','action'=>'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Entrar');
Modell
class Master extends AppModel{
public $name = 'Master';
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Usuario requerido.'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Senha requerida.'
)
)
);
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
Ich weiß nicht warum, es gibt diese Fehler ... Das scheint alles ok!
Ich verändert ein Brief von Sicherheit.Salz, als er fragte ..
Mir helfen 🙂
Ich brauche es für die Arbeit
Das Passwort wahrscheinlich nicht übereinstimmt oder Ihre Sitzung ist nicht konfiguriert propertly. Ist das Ergebnis
debug(AuthComponent::password($this->data[$this->alias]['password']))
das gleiche wie das Passwort mit dem Wert in der Datenbank?
InformationsquelleAutor Jhonatan G. | 2013-08-07
Du musst angemeldet sein, um einen Kommentar abzugeben.
ist eine schlechte Idee.
die erste wird Sie einloggen,
der zweite Anruf wird dann natürlich false zurück (da Sie bereits angemeldet sind).
Wenn Sie wirklich brauchen, um dies zu testen Weg, halt den code:
InformationsquelleAutor mark
Ich hatte das gleiche problem und wie es behoben war für mich ändern $this->alias Nutzer, so dass beforeSave() sieht jetzt aus wie
InformationsquelleAutor Justice O.