2016-03-08 82 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

相關問題