Home Ask Login Register

Developers Planet

Your answer is one click away!

Andy Holmes February 2016

Laravel 5.1 - Authenticate Username, Password AND if confirmed = 1

Pulling my hair out over what seems a simple task. I use the username instead of email in my AuthController using the following code:

 * Set the login system to use username instead of email address
 * @var string
protected $username = 'username';

This has worked fine for a long time (when I wasn't planning on users activating their accounts). However, now I need users to activate their accounts, I know I need to do additional checks on login before they can see their dashboard.

I have modified the postLogin() method below, to what I thought would be correct:

public function postLogin(Request $request)
    $this->validate($request, [
        'username' => 'required', 'password' => 'required',

    $credentials = $request->only('username', 'password');
    $credentials = array_add($credentials, 'confirmed', '1');

    if ($this->auth->attempt($credentials, $request->has('remember')))
        return redirect()->intended($this->redirectPath());

    return redirect($this->loginPath())
                ->withInput($request->only('username', 'remember'))
                    'username' => $this->getFailedLoginMessage(),

But all I get is the following error:

Undefined property: App\Http\Controllers\Auth\AuthController::$auth

What is it that i'm doing wrong?



nikistag February 2016

Just one glitch that I see there.

if ($this->auth->attempt($credentials, $request->has('remember')))

should be

if (Auth::attempt($credentials, $request->has('remember')))

Post Status

Asked in February 2016
Viewed 2,768 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life