Laravel 哈希
散列是将字符串转换为较短的固定值或表示原始字符串的键的过程。laravel使用 哈希 门面,它提供了一种以散列方式存储密码的安全方式。
基本用法
以下屏幕截图显示了如何创建一个名为 passwordcontroller 的控制器,用于存储和更新密码 -

以下几行代码解释了 passwordcontroller 的功能和用法-
namespace app\http\controllers;
use illuminate\http\request;
use illuminate\support\facades\hash;
use app\http\controllers\controller
class passwordcontroller extends controller{
/**
* updating the password for the user.
*
* @param request $request
* @return response
*/
public function update(request $request){
// validate the new password length...
$request--->user()->fill([
'password' => hash::make($request->newpassword) // hashing passwords
])->save();
}
} 哈希密码使用 make 方法存储。这种方法允许管理在laravel中普遍使用的 bcrypt 哈希算法的工作因子。
验证密码反哈希
您应该使用散列验证密码以检查用于转换的字符串。为此,您可以使用 检查 方法。这在下面给出的代码中显示 -
if (hash::check('plain-text', $hashedpassword)) {
// the passwords match...
} 请注意, check 方法会将纯文本与 hashedpassword 变量进行比较,如果结果为true,则返回true值。


