将普通密码转换为Laravel加密密码 [英] Converting plain password to Laravel encrypted password

查看:196
本文介绍了将普通密码转换为Laravel加密密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为用户"的表,其中有用户的用户名和密码.

I have a table called "users" where I have username and password from my users.

密码为纯文本.现在,我使用Laravel 5.4和Auth创建了一个新站点.

The passwords are in plain text. Now I've created a new site with Laravel 5.4 and Auth.

因此,如果用户要登录到我的网站,则需要将密码纯文本格式转换为加密的新密码.

如何从Auth中获取盐",以及一种从我的普通密码和盐"中获取加密密码的工具.原因是因为我在用户表中创建了一个新列,所以我想在其中放置使用查询加密的密码.

How can I get the "salt" from my Auth and also a tools to get the encrypted password from my plain password and "salt". The reason is because I created a new column in my users table so I want to put there the password encrypted using a query.

感谢您的帮助!

推荐答案

Laravel使用bcrypt()来哈希密码.假设您已将纯文本密码存储在users.password中,则只需要循环遍历并bcrpyt().

Laravel uses bcrypt() to hash passwords. Assuming you have the plain text passwords stored in users.password, you just need to loop through and bcrpyt() them.

\App\User::get()->each(function ($user) {
    $user->password = bcrypt($user->password);
    $user->save();
});

上面的代码将用散列值覆盖存储在users.password中的纯文本值.完成此操作后,用户应该可以使用Laravel的auth登录.此外,您将无法检索用户的纯文本密码.很好,这就是对密码进行哈希处理的全部要点.

The above code will overwrite the plain text value stored in users.password with the hashed value. After you do this, user's should be able to log in with Laravel's auth. Additionally, you will not be able to retrieve the user's plain text password. This is good, and is the whole point of hashing passwords.

这篇关于将普通密码转换为Laravel加密密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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