显示未定义索引的错误:密码

时间:2016-12-13 09:26:00

标签: php laravel

我的会话控制器我为验证电子邮件,登录和更改密码编码,但收到错误

  

EloquentUserProvider.php第116行中的ErrorException:   未定义的索引:密码。

并从行代码中获取错误

if (!Auth::attempt($credentials_verifiy))

<?php
namespace App\Http\Controllers;

use Request;
use Response;
//----models--------
use App\Site;
use App\Jobs;


use Auth;
use DB;
use Validator;
use Redirect;

//use Illuminate\Support\Facades\Validator;
use Illuminate\Support\MessageBag;
class SessionController extends Controller {

    public function index(){
        return Redirect::to('login')->with('alert-success', 'test awrnning message.');
    }
    public function store()
    {
             $input = Request::only('username', 'email', 'password');
             $credentials = [
                 'username' => Request::get('username'),
                 'password' => Request::get('password')
             ];

            if (!Auth::attempt($credentials))
            {
                return Redirect::back()->with('alert-danger', 'Username or password do not match.');
            }
            else
            {
                $credentials_verifiy = [
                    'verified_email' => '1'
                ];
                if (!Auth::attempt($credentials_verifiy))
                {
                    return Redirect::back()->with('alert-danger', 'Please verify your email.');
                }
                else
                {
                    if(Auth::user()->last_login_at=='' || Auth::user()->last_login_at==null)
                    {
                        return redirect('/change_password');
                    }
                    else
                    {
                        return redirect('/tests');
                    }
                }
            }
    }
}

2 个答案:

答案 0 :(得分:3)

为了跳过此异常,您可以使用此行代码

array_get('password', $input);

如果数组$input没有索引password它将不会抛出异常,它将返回null,您可以使其返回您想要的内容:array_get('password', $input, ' ');

答案 1 :(得分:1)

$credentials中的

Auth::attempt($credentials)数组应包含password键的值,这就是您收到错误的原因。 Auth::attempt()正在使用的hardcoded in validateCredentials()方法:

public function validateCredentials(UserContract $user, array $credentials)
{
    $plain = $credentials['password'];

    return $this->hasher->check($plain, $user->getAuthPassword());
}