mardi 31 mai 2016

!Auth::attempt won't compare the records in database

The attempt method won't get the right values in my database. It always fail when I input right values. I create a Seeder which insert a values in my database. I hash my password, I'm not sure if hashing that cause why it won't redirect me to home page.

AdminTableSeeder

class AdminTableSeeder extends Seeder
{
public function run()
{
    DB::table('admin')->delete();

    $admin = array(
    array('username' => 'admin',
          'password' => Hash::make('admin'))
    );

    DB::table('admin')->insert($admin);
}
}

AdminController

public function postAdminLogin(Request $request)
{
    $this->validate($request, 
    [
        'username' => 'required|max:20',
        'password' => 'required|min:5',
    ]);

    if(!Auth::attempt($request->only(['username','password']), $request->has('remember')))
    {
        return redirect()->back()->with('info', 'Could not sign in with those details.');
    }

    return redirect()->route('admin')
    ->with('info', 'Successfully logged in');
}

loginadmin.blade.php

<form class = "form-vertical" role = "form" method = "post" action = "">

            <div class = "form-group ">
                <label for = "username" class = "control-label">Username</label>
                <input type = "text" name = "username" class = "form-control">

                @if ($errors->has('username'))
                    <span class = "help-block"></span>
                @endif
            </div>

            <div class = "form-group ">
                <label for = "password" class = "control-label">Password</label>
                <input type = "password" name = "password" class = "form-control">

                @if ($errors->has('password'))
                    <span class = "help-block"></span>
                @endif
            </div>

            <div class = "checkbox">
                <label>
                    <input type = "checkbox" name = "remember">Remember me</input>
                </label>
            </div>

            <div class = "form-group">
                <button type = "submit" class = "btn btn-default">Login</button>
            </div>

            <input type = "hidden" name = "_token" value = "">

</form>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WuzyOf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire