0

hi guys i have an simple application with laravel and i try to add a user Authentication to my app , this is my route.php file :

Route::model('task', 'Task');


Route::get('/login', 'HomeController@ShowLogin');
Route::post('/login', 'HomeController@doLogin');

Route::get('/logout' , 'HomeController@doLogout');


Route::group(array('before'=>'auth'), function(){

Route::get('/', 'TasksController@home');
Route::get('/create', 'TasksController@create');
Route::get('/edit/{task}', 'TasksController@edit');
Route::post('/edit', 'TasksController@doEdit');
Route::post('/create' , 'TasksController@saveCreate');
Route::get('/delete/{task}' , 'TasksController@delete');
Route::post('/delete', 'TasksController@doDelete');

Route::get('/task/{id}' , 'TasksController@show')->where('id', '\d+');

});

this is my HomeController.php ;

class HomeController extends BaseController {

public function showLogin()
{
    return View::make('login');
}
public function doLogin()
{
    $userdata = array(
        'username' => Input::get('username'),
        'password' => Input::get('password')
    );
    dd(Auth::attempt($userdata));

    if(Auth::attempt($userdata))
    {

        return Redirect::to('/');
    }
    else
    {
        return Redirect::to('login');
    }
}

public function doLogout()
{
    Auth::logout();
    return Redirect::to('login');
}

}

and this is my login.blade.php file :

@extends('layout')
@section('content')
<section class="header section-padding">
<div class="background">&nbsp;</div>
<div class="container">
    <div class="header-text">
        <h1>Learning Laravel: The Easiest Way</h1>
        <p>
            Showing a single task <br/> using route parameter!
        </p>
    </div>
</div>
</section>
<div class="container">
<section class="section-padding">
    <div class="jumbotron text-center">
        <h1>
            Login
        </h1>
        <P>
            {{ $errors->first('username')  }}
            {{ $errors->first('password') }}
        </P>

        {{ Form::open(['url' => '/login', 'class' => 'form']) }}
        <div class="form-group">
            {{ Form ::label('username', 'Username:') }}
            {{ Form::text('username')}}
        </div>
        <div class="form-group">
            {{ Form::label('password', 'Password:') }}
            {{ Form::password('password') }}
        </div>
        <div class="form-group">
            {{ Form::submit('Login', ['class' => 'btn btn-primary']) }}
        </div>
        {{ Form::close() }}
    </div>
</section>
</div>
@stop

when i input any username and password i got no error and i never login , and i redirect to login page and dd() always return bool(false), can any one help that , and explain more about Authentication in Laravel , Thank U :)

Edit

and this is my model/User.php and i dont add any code to this :

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;


    protected $table = 'users';

    protected $hidden = array('password', 'remember_token');

}

i create my user table manually

5
  • can you past your user model code? Commented Nov 2, 2014 at 15:42
  • how u save the user ? Commented Nov 2, 2014 at 16:01
  • @KalhanoToressPamuditha i thought we need save user if only we want to create a user but here i want to check a user exists in db or not Commented Nov 2, 2014 at 16:02
  • ok seems like u can get the username and password correctly in the doLogin() , is ur password field hashed in the database ? Commented Nov 2, 2014 at 16:05
  • no i manually add users to db and i don't hash them Commented Nov 2, 2014 at 16:06

1 Answer 1

1

Auth::attempt($userdata) method will hash the password in $userdata array and check that hashed password with the database value,

so you need hashed passwords in the database,

to verify that,

please change the password in the database to $2y$10$3S3yDwfkwwLghedu4AoaTe//61QTaNC0ycTdp8hLfHtQS4XrgBPQy , and use a for the password field in the form

$2y$10$3S3yDwfkwwLghedu4AoaTe//61QTaNC0ycTdp8hLfHtQS4XrgBPQy is the laravel hashed password for a.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.