2016-03-08 101 views
0

我正在开发一段时间的网站。我总是使用Laravel Auth::attempt进行身份验证,之前它运行良好,但现在它不起作用。我刚刚从PHPMyAdmin中删除了我的数据库并迁移了所有的迁移。此后Auth::attemptHash::check总是返回false。Laravel 5.0 Hash :: check和Auth :: Attempt总是返回false

这是我DevelopmentSeeder:

\App\Models\Employee\UserAccount::create([ 
    'AccountName' => 'admin', 
    'Username' => 'superadmin', 
    'Password' => \Illuminate\Support\Facades\Hash::make('hello'), 
    'UserType' => 'Super Admin' 
]); 

我在我的控制器试过这样:

$acc = UserAccount::where('AccountName', '=', 'admin') 
        ->where('Username', '=', 'superadmin') 
        ->where('IsActive', '=', 1)->get(); 
if(count($acc) > 0){ 
    dd(Hash::check('hello', $acc[0]->Password)); 
} 

模具转储始终返回false。我已经尝试过Auth::attempt,但它也会返回false。

这是我的UserAccount型号:

use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Authenticatable; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 
class UserAccount extends Model implements AuthenticatableContract, CanResetPasswordContract { 

    use Authenticatable, CanResetPassword; 

    protected $table = "UserAccounts"; 
    protected $fillable = ['AccountName', 'EmployeeID', 'Username', 'Password', 'Email', 'UserType']; 
    protected $hidden = ['Password', 'remember_token']; 

    public function getAuthIdentifier(){ 
     return $this->getKey(); 
    } 

    public function getAuthPassword(){ 
     return $this->Password; 
    } 

    public function getRememberToken(){ 
     return $this->remember_token; 
    } 

    public function setRememberToken($value){ 
     $this->remember_token = $value; 
    } 

    public function getRememberTokenName(){ 
     return 'remember_token'; 
    } 

    public function setPasswordAttribute($password){ 
     $this->attributes['Password'] = bcrypt($password); 
    } 

    public function getEmailForPasswordReset(){ 
     return $this->Email; 
    } 
} 

回答

1

我发现在哪里误入歧途。因此,在我的UserAccount模型中,我将密码存储在数据库中之前,先设置密码setPasswordAttributebcrypt

但是在我的DevelopmentSeeder中,我加密了create()方法中的密码。

因此,密码得到双重加密。

解决方案是删除DevelopmentSeeder中的Hash::make

相关问题