Laravel 在不破坏身份验证的情况下加密用户电子邮件

问题描述 投票:0回答:2

我想在数据库中加密电子邮件地址。使用修改器,我可以为我的 laravel 网络应用程序加密和解密模型属性。

问题是电子邮件属性用于身份验证。因此,对电子邮件使用突变器似乎完全破坏了我的应用程序,大概是通过 Auth::check()、id()、login() 等

我看着编写自定义身份验证驱动程序,但无法让它工作。

我只是想知道在哪里重载模型以添加加密和解密,这将与 laravels 身份验证方法兼容。

php authentication encryption laravel-4
2个回答
0
投票

除了加密之外,您还需要在自定义 Auth 提供程序中实施某种

盲索引

有很多方法可以搞砸这样的实现。请务必参考 CipherSweet 文档(尤其是其security designinternals)以确保您的实施一切正常。

或者,您可以只使用 CipherSweet 为您的自定义

Auth
提供商提供支持,而不必自己担心密码学实施。


0
投票

我知道为时已晚,但这是我的实现: 我不知何故以一种肮脏的方式处理了这件事。 在使用 laravel fortify 之前,我必须首先使用原始查询获取用户的电子邮件,以防止触发模型观察者:

$operator = Operator::query()->whereBlind('email','operator_email_index', strtolower($request['email']))->first();

如果操作员存在则覆盖电子邮件请求并直接从模型获取电子邮件:

if($operator) { $credentials['email'] = DB::table('operator_operators')->where('id',$operator->id)->first()->email; }
and then use the default Auth::Attempt method
$this->guard()->attempt( $credentials, $request->filled('remember') );

但是使用 fortify 您可以使用 authenticateUsing 方法轻松覆盖尝试并防止额外的查询。

这是我的尝试登录功能:

 protected function attemptLogin(Request $request)
{

    $credentials = $this->credentials($request);
    $operator = Operator::query()->whereBlind('email','operator_email_index', strtolower($request['email']))->first();
    if($operator) {
        $credentials['email'] = DB::table('operator_operators')->where('id',$operator->id)->first()->email;
    }
    return $this->guard()->attempt(
        $credentials, $request->filled('remember')
    );
   
}
© www.soinside.com 2019 - 2024. All rights reserved.