在Auth :: attempt上禁用哈希 [英] Disable hashing on Auth::attempt

查看:80
本文介绍了在Auth :: attempt上禁用哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用没有哈希密码的旧数据库,而且由于该数据库已连接到Runnable JAR,因此也需要对其进行哈希处理.

I am working with an old database without hashed passwords, also this database needs to be unhashed since it is connected to a Runnable JAR.

我已尽一切努力将其与Laravel 5.3连接,并且可以正常工作,但是..登录时,它总是返回false.

I did everything to connect it with Laravel 5.3 and it worked, but.. When comes to login it always return false.

这是功能代码:

public function login(Request $request)
{
    $this->validate($request, [
        'account' => 'required|alpha_num|exists:accounts,account',
        'password' => 'required|alpha_num|min:4',
    ]);


    if(Auth::attempt(['account' => $request->account, 'password' => $request->password])){
        return redirect()->route('account');
    }

    return redirect()->back()->withInput();
}

我得出的结论是,Auth :: attempt通过视图对给定的密码进行哈希处理,并且与数据库中未哈希的密码进行比较时,返回false.

I came to the conclusion that Auth::attempt hashes the given password through the view and when comparing to the unhashed one in the database, returns false.

我该如何解决?

谢谢.

推荐答案

您将需要使用手动身份验证.

$user = User::where('account', $request->account)
            ->where('password', $request->password)
            ->first();

if($user) {
    Auth::loginUsingId($user->id);
    // -- OR -- //
    Auth::login($user);
    return redirect()->route('account');
} else {
    return redirect()->back()->withInput();
}

这篇关于在Auth :: attempt上禁用哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆