Laravel 5.1哈希检查总是返回false

时间:2016-12-04 05:49:47

标签: php laravel authentication bcrypt laravel-authorization

我是laravel的新手。请帮我。

这是我的用户模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    public $timestamps = false;

    /*
     *  mass assignable attributes
     */
    protected $fillable = [
        'user_id',
        'email',
        'uuid',
        'pwd_expired',
        'two_factor_auth_required',
        'is_editable',
        'version',
        'first_name',
        'last_name',
        'pwd_hash',
        'merchant_id'
    ];
}

这是我的身份验证功能。

public function authenticateUser(Request $data){

        // checking if there any user for given email
        if( $this->IsEmailUnique($data ->email)){
            return $this->setHeaders([
                'status' => 'fail',
                'msg' => 'No user recorded with given email address',
            ], 404 );
        }
        // if there is a user relevant to given email address
        else{

            // getting user relevant to given email
            $user = $this -> getSingleUserByEmail($data->email);

            // checking for password matching
            if( Hash::check($data -> password, $user -> pwd_hash)){

                return $this->setHeaders([
                    'status' => 'success',
                    'msg' => 'User successfully authenticated',
                    'user' => $user,
                    'merchant' => Merchant::where('merchant_id', $user -> merchant_id)->get()
                ], 200 );
            }
            // if authentication failed
            else{
                return $this->setHeaders([
                    'status' => 'fail',
                    'msg' => 'Invalid password for given username',
                ], 403 );
            }
        }

    }

我使用自己的用户模型。用户列中的密码字段超过60个字符。一切正常,直到Hash :: check。我已经用var_dumps进行了测试。但是&#34; Hash :: check($ data - &gt; password,$ user - &gt; pwd_hash)&#34;总是返回false。请帮帮我。

此外,我还在我的UserController中编写了所有登录信息。我只需要功能。

0 个答案:

没有答案