【问题标题】:how to work with laravel email encryption如何使用 laravel 电子邮件加密
【发布时间】:2020-02-28 10:43:40
【问题描述】:

您好,我正在尝试对用户表中的电子邮件进行加密,并通过加密更改身份验证过程的“电子邮件”,但对我不起作用,不断返回我的电子邮件与记录不匹配。 我的 RegisterController 是:

User::create([
            'name' => $data['name'],
            'email' => sha1(sha1($data['email'])),
            'password' => Hash::make($data['password']),
            'referred_by' => $referred_by
        ]);

我正在尝试使用 laravel 进行手动身份验证:https://laravel.com/docs/6.x/authentication#authenticating-users

我的登录控制器:

public function authenticate(Request $request)
    {
        $credentials = $request->only(sha1(sha1('email')), 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->intended('dashboard');
        }
    }

注意:我知道 sha1 不好,但我认为电子邮件的双重 sha1 将很难破解。

我也无法准确找到进行身份验证的位置(因为我在 3 周前开始学习 laravel),我可以将用户输入的电子邮件字段切换为 sha1 x2,以便与用户表电子邮件进行比较。

谢谢

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    在这里找到答案:https://laracasts.com/discuss/channels/laravel/encrypt-email-field-in-users-table

    通过以下方式更改 AuthenticatesUsers 的登录功能:

    public function login(Request $request)
        {
            if (Auth::attempt(['email'  => sha1(sha1($request->email)), 'password' => $request->password])) {
                return redirect()->intended();
            } else {
                return $this->sendFailedLoginResponse($request);
            }
        }
    

    感谢 saaz。

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 2015-10-27
      • 2010-09-07
      • 2020-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      相关资源
      最近更新 更多