Sanm
Sanm

Reputation: 19

Error on user authentication in laravel

I am a beginner of laravel framework. I am now having problem in authentication in laravel 5.2. I tried but I can't find error.

Email and password is correct but it is redirecting to login page.

Here is my DB

+----+-------+-----------------+----------+-------+----------------+---------------------+---------------------+
| id | name  | email           | password | phone | remember_token | created_at          | updated_at          |
+----+-------+-----------------+----------+-------+----------------+---------------------+---------------------+
|  1 | Admin | [email protected] | 111111   |       | NULL           | 2017-01-03 05:40:06 | 2017-01-03 05:40:06 |
+----+-------+-----------------+----------+-------+----------------+---------------------+---------------------+

Here is UserController

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Auth;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\User;

use DB;


class UserController extends Controller
{
    public function index() 
    {
        if( !Auth::check() ) {
            return view('user/index');
        } else {
            return view('user/profile');
        }
    }

    public function login(Request $request)
    {
        if( Auth::attempt( array( 

            "email" => "[email protected]",
            "password" => "111111",

        ) ) ) {
            return redirect('user/profile');
        } else {
            return redirect('user/login');
        }
    }
}

Upvotes: 0

Views: 58

Answers (1)

Haseena P A
Haseena P A

Reputation: 17416

In Database you need to store password in encrypted format.Auth::attempt() will convert the password into encrypted form and compare with the password in database.

During data insertion into the database you need to use

bcrypt($password);

Upvotes: 3

Related Questions