4

我在 php 中有一个现有项目。我正在将项目从核心移动到 laravel。但我在从现有表中实现管理员身份验证时遇到问题。当我对此进行了大量研究时,我发现有一些命令可以自动创建身份验证功能。

请有人帮助我使用 laravel 模型和现有表手动创建身份验证过程。

4

1 回答 1

0

我认为您可以执行以下步骤:

  1. 通过更改或添加以下列来修改现有的 Laravel 身份验证表:

    • username(细绳)
    • password(细绳)
    • created_at(约会时间)
    • updated_at(约会时间)
    • remember_token(细绳)
  2. 将现有密码更改为Bcrypt哈希类型,这是 Laravel 中的默认哈希方法,或者阅读类似的指南强制 Laravel 在您现有的哈希函数中工作。

  3. 制作 LaravelUser模型。你可以像使用 Laravel Migration 的任何教程一样进行操作。它必须是这样的:

    <?php namespace App;
    
    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Passwords\CanResetPassword;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
    use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
    
    class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
    
        use Authenticatable, CanResetPassword;
    
        protected $table = 'users';
    
        protected $fillable = ['password', 'username', 'email'];
    
        protected $hidden = ['password', 'remember_token'];
    }
    
  4. 阅读Laravel 认证课程指南。这很简单,例如您可以使用功能检查用户是否登录Auth::check(),或者尝试像这样登录:

    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
    }
    
于 2016-08-13T12:16:25.337 回答