如何将原始用户密码发送到他的邮箱(加密前)

How to send original users password to his mail (before bcryption)

在我的系统中用户无法注册。管理员在管理面板中添加所有用户并告诉他们您的密码是 "xxx"。现在我需要向用户发送邮件。其中包含用户电子邮件和用户密码。系统运行良好。但有一个例外。在邮件中,密码是加密的。我该如何解决?我没有任何线索。我正在使用 observers。在模型中:

    public static function boot()
{
    parent::boot();
    self::created(function () {
        $customer = Customer::latest()->get()->first();
        Mail::send('emails.user_login_informations', ['customer' => $customer], function($message) use($customer) {
            $message->to($customer->email, $customer->name, $customer->password)
                ->subject('Login Information');
        });
    });
}

ps:这是有效的。在我的邮件中:

Your email: xxx@example.com 
Your Password: y$/GW5XNH9KGU.Nz05PZHFJuKb2ldhwYhS8oMX9e7HJIuFNJ

但这看起来像:

Your email: xxx@example.com 
Your Password: 123

您对用户密码进行哈希处理以提高安全性。散列功能是一种单向散列,因此无法逆转。

更好的方法是创建密码重置令牌并将其发送给用户。因此用户可以使用电子邮件地址/令牌组合设置新密码。要增加此方法,您可以让令牌在 30 分钟左右后过期。

您可以创建一个临时密码字段并在用户激活时将其删除。我需要这个作为真实世界的例子。例如:

Event::listen('rainlab.user.activate', function($user) {
    $user->temp_password = null;
    $user->save();
});

User::saving(function ($user) {
    $password = post('User.password');
    if ($password && ! $user->attributes['is_activated']) {
        $user->temp_password = $password;
    }
});

虽然如上所述,这包含很大的安全风险。