0

I already search for this thing but I'm really new at this and I can't figure it out how to make it work. I'm using a project without many changes so I have my User.php as it comes but I add this:

protected $fillable = ['username', 'email', 'password'];//GEN_ID_Usuario

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = ['password', 'remember_token'];

/**
* The eloquent relation to assigment a "formulario" model.
*
*/

public function getAuthPassword()
{
    return $this->Usu_Contrasenia;
}

And I have my AuthController as default but I added this:

public function authenticate()
{
    $email = $input['email'];
    $password = $input['password']; 
    if (Auth::attempt(array('Usu_Email' => $email, 'Usu_Contrasenia' => 
    $password)))        
    {
        return redirect()->intended('dashboard');
    }
}

Everything else in the project it's by default, just trying to use username, email and password as: Usu_Nombre, Usu_Email and Usu_Contrasenia.

Mel
  • 1
  • 3
  • I am not sure if this works for you : http://stackoverflow.com/questions/26002552/laravel-4-custom-named-password-column/26002831#26002831 – Hardy Mathew May 07 '15 at 21:06
  • Change `Auth::attempt(array('Usu_Email' => $email, 'Usu_Contrasenia' => $password)` to `Auth::attempt(array('Usu_Email' => $email, 'password' => $password)`. Now `getAuthPassword()` will properly kick in. – user2094178 May 08 '15 at 00:48
  • @user2094178 and Hardy Mathew I did what you said and this happend... QueryException in Connection.php line 624: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select count(*) as aggregate from `Gen_Usuario` where `email` = melis.inf@gmail.com) – Mel May 08 '15 at 20:21
  • Leave `'Usu_Email'` as it is. – user2094178 May 08 '15 at 22:57
  • @user2094178 like this: public function authenticate() { $password = $input['password']; if (Auth::attempt(array('Usu_Email', 'password' => $password))) { return redirect()->intended('dashboard'); } } Because I did it this way and still get the error :( I'm so lost. – Mel May 09 '15 at 00:57

1 Answers1

0

Based on the comments exchange, try the following:

public function authenticate()
{
    $email = $input['email'];
    $password = $input['password']; 
    if (Auth::attempt(array('Usu_Email' => $email, 'password' => 
    $password)))        
    {
        return redirect()->intended('dashboard');
    }
}

Keep in mind the stored password must be properly hashed for Auth:attemp() to work as intended.

user2094178
  • 9,204
  • 10
  • 41
  • 70
  • Don't forget, you have to update `$fillable` and `$hidden` in your model to reflect the correspondent table schema. – user2094178 May 09 '15 at 17:31
  • I did it, I changed the things, except that I don't know about the hashed but I hope I could even register but I couldn't... Got the same error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select count(*) as aggregate from `Gen_Usuario` where `email` = melis.inf@gmail.com)... As I said I'm so new at this so I don't have idea :'( But thank you so much for your time. – Mel May 10 '15 at 01:13