【问题标题】:Laravel custom Authenication with different fields具有不同字段的 Laravel 自定义身份验证
【发布时间】:2017-12-29 23:42:09
【问题描述】:

我的数据库中有一个名为 (users_system) 的表,其中包含:

  • user_id
  • user_pass(纯文本)

...其他一些字段

考虑到(Auth::attempt) 仅处理电子邮件和哈希密码,我想要的是能够使用这两个字段进行 laravel(5.2) 身份验证。

那有可能吗?如果可以,该怎么做?

【问题讨论】:

    标签: php laravel authentication laravel-5.2


    【解决方案1】:

    您可以手动检查凭据和登录用户:

    $userSystem = UserSystem::where('user_id', $userId)->where('user_pass', $password)->first();
    if (!is_null($userSystem)) {
        // Manually login user.
        $user = User::find($userId);
        Auth::login($user);
    }
    

    但是使用纯文本密码是一个糟糕的主意。你不应该在真正的应用程序中这样做。

    【讨论】:

    • 这给出了以下错误 传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable,给定 null
    • @BecauseGeek 那是因为您使用了错误的 ID 或其他东西。确保$user = User::find($userId) 获取用户。例如,如果 $userId = 5 并且您没有具有此 ID 的用户,它将返回 null
    • 你说得对,我在用户模型中更改了我的表主键并且它工作了,但是现在我在执行 Auth::logout(); 时遇到了另一个问题;这是: 错误消息:ORA-00904:“UPDATED_AT”:无效标识符位置:52 语句:更新 ums.users_password 设置 remember_token = :p0, updated_at = :p1 其中 user_sys_id = :p2 我猜是因为我没有更新记住我的令牌,所以如何解决这个问题
    • @BecauseGeek 这个错误与你的问题无关,所以你应该问另一个问题并在那里发布所有相关代码。
    猜你喜欢
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 2012-09-22
    • 2014-03-30
    • 2016-04-18
    • 1970-01-01
    • 2011-06-23
    相关资源
    最近更新 更多