mardi 8 mars 2016

Laravel 5.0 Hash::check and Auth::Attempt always return false

I'm developing a website for some time now. I always use Laravel Auth::attempt for authentication, it works fine before. But now it didn't work anymore. I just deleted my database from PHPMyAdmin and migrate all of my migrations. Then Auth::attempt and Hash::check always return false since then.

This is my DevelopmentSeeder :

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

I tried this in my controller :

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

The die dump always returns false. I already tried Auth::attempt but it returns false too.

This is my UserAccount model :

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;
    }
}

Please help :(



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire