# Auth não libera login

**URL:** <https://discourse.cakephp.org/t/auth-nao-libera-login/3415>\
**Category:** Need Help\
**Created:** [October 29, 2017, 1:25am UTC](https://discourse.cakephp.org/t/auth-nao-libera-login/3415 "2017-10-29T01:25:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![horacio](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/horacio/32/858_2.png) [@horacio](https://discourse.cakephp.org/u/horacio)\
**Post date:** [October 29, 2017, 1:25am UTC](https://discourse.cakephp.org/t/auth-nao-libera-login/3415/1 "2017-10-29T01:25:11Z")

</div>

Estou estudando CakePHP e criei um projeto para treina login, mas não importa o que faço, o login/senha sempre nega o acesso. aí vão os códigos

public function initialize()  
{  
//appController  
parent::initialize();

```
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');

//---------------------------------
$this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => [
                'username' => 'email',
                'password' => 'password'
            ]
        ]
    ],
    'loginAction' => [
        'controller' => 'Users',
        'action' => 'login'
    ],
     // If unauthorized, return them to page they were just on
    'unauthorizedRedirect' => $this->referer()
]);
//------------------------------------

$this->Auth->allow(['display', 'view', 'index']);

```

}  
já no users contoller

public function initialize()  
{  
parent::initialize();  
// Add the ‘add’ action to the allowed actions list.  
$this-\>Auth-\>allow([‘logout’, ‘add’]);  
}

public function logout()  
{  
$this-\>Flash-\>success(‘You are now logged out.’);  
return $this-\>redirect($this-\>Auth-\>logout());  
}

```
public function login()

```

{  
if ($this-\>request-\>is(‘post’)) {  
$user = $this-\>Auth-\>identify();  
if ($user) {  
$this-\>Auth-\>setUser($user);  
return $this-\>redirect($this-\>Auth-\>redirectUrl());  
}  
$this-\>Flash-\>error(‘Your username or password is incorrect.’);  
}  
}  
já página de login:

{

# Login
 \<?= $this-\>Form-\>create() ?\> \<?= $this-\>Form-\>control('email') ?\> \<?= $this-\>Form-\>control('password') ?\> \<?= $this-\>Form-\>button('Login') ?\> \<?= $this-\>Form-\>end() ?\> } a tabela do banco:

CREATE TABLE users (  
id INT AUTO\_INCREMENT PRIMARY KEY,  
email VARCHAR(255) NOT NULL,  
password VARCHAR(255) NOT NULL,  
created DATETIME,  
modified DATETIME  
);  
enfim…o que tá errado???obrigado a todos!! Horácio
