0
votes

I got the next code:

    public function registrarUsu(){
$datosregistro = array(
    null, 
    "Carlos Delgado",
    "Gonzalez Padron",
    Input::get('username'),
    Hash::make(Input::get('contrasena')),
    );
$consulta = DB::insert('insert into usuarios (id, nombres, apellidos, nick_name, contrasena) values ( ?, ?, ?, ?, ?)', $datosregistro);
DB::commit($consulta);
}

This what it does is; grabs the username and password from a simple login form which I early created, it does what it does, grabs all the data and saves it to the database (The static fields are just for demonstration). The problem is when i try to authenticate the user with the next function:

    public function loguearUsu(){
        $datosdeusu = array(
            'nick_name' => Input::get('username'),
            'contrasena' => Input::get('Contrasena'),
                            );

if(Auth::attempt($datosdeusu)){
    return Redirect::to('/');
}}

I think that the problem is the password, every time i tried to login it just return false, but if I use a var_dump it shows the username and password just as they are in the database, so what am i doing wrong?

2

2 Answers

0
votes
 public function loguearUsu(){
    $datosdeusu = array(
        'nick_name' => Input::get('username'),
        'contrasena' => Input::get('Contrasena'),
                        );

   if(Auth::attempt($datosdeusu)){
       return Redirect::to('/');
    }
}

your Input::get('contrasena') on register is not the same as login, recheck

anyway you can use this instead (if the input is two field : username,password)

   if(Auth::attempt(Input::all())){

        return Redirect::to('main');

    }
0
votes

You may need to update your user model because you are using a non standard field for the password. Try adding this to your user model. Hope that helps.

public function getAuthPassword()
{
     return $this->attributes['contrasena'];
}