我在谷歌上搜索了很多,但不幸的是没有找到有效的解决方案.

I know its a bad technique, but I need to send user its password by email.

I have manage to sent user Hash password, but i am unable to decrypt this password.

The following is the procedure i am using.

    $results = DB::select("select * from dockl_users where email='" . Input::get('email')  ."';");      

                foreach($results as $data){
                $password=          $data->password;
                $email=             $data->email;

               }

            Mail::send('passwordRecovery', array('email' =>$password), function($message)
            {
                $message->to(Input::get('email') )->subject('Password Recovery');
            });

The above code send Encrypted password to the user by email but when i try to decrypt, it gives me following error message.

$decrypt= Crypt::decrypt($data->password);  

数据无效.

throw new DecryptException("数据无效.");

请指导我如何做到这一点..

推荐答案

Short answer is that you don't 'decrypt' the password (because it's not encrypted - it's hashed).

The long answer is that you shouldn't send the user their password by email, or any other way. If the user has forgotten their password, you should send them a password reset email, and allow them to change their password on your website.

Laravel has most of this functionality built in (see the Laravel documentation - I'm not going to replicate it all here. Also available for versions 4.2 and 5.0 of Laravel).

For further reading, check out this 'blogoverflow' post: Why passwords should be hashed.

Laravel相关问答推荐

Laravel FAKER语法

Laravel 10 - 没有 $append 属性的Eloquent 的热切加载

Laravel 语法 GroupBy 获取列到数组

Inertiajs - 使用链接组件添加记录但无法在不使用表单的情况下清除文本区域

如何计算具有特定 ID Laravel 的行

LARVAL SAVE 中的关系有

API GET 请求得到与数据库记录不同的结果

运行Docker时,安装PHP8.1时返回错误

如何保存/重定向 Laravel Artisan 命令的输出?

Laravel:使用 Input::old 时 textarea 不会重新填充

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

Laravel:Blade foreach 循环 bootstrap 列

laravel url 验证变音符号

如何使用 Eloquent Laravel 更新集合

路由模型绑定不起作用

Laravel Passport Route [login] 未定义

加载模型的所有关系

Filesystem.php 中的 ErrorException

如何将对象(模型类型对象)插入到 Laravel 中特定索引号的集合对象中?

无法捕获 Carbon 抛出的异常