首页 > php框架 > Laravel > 正文

Laravel - 哈希

PHPz
发布: 2024-08-27 11:56:54
原创
1238 人浏览过

Hashing is the process of transforming a string of characters into a shorter fixed value or a key that represents the original string. Laravel uses the Hash facade which provides a secure way for storing passwords in a hashed manner.

Basic Usage

The following screenshot shows how to create a controller named passwordController which is used for storing and updating passwords −

Laravel - 哈希

The following lines of code explain the functionality and usage of the passwordController

<?php

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([
         &#39;password&#39; => Hash::make($request->newLaravel - 哈希) // Hashing passwords
      ])->save();
   }
}
登录后复制

The hashed passwords are stored using make method. This method allows managing the work factor of the bcrypt hashing algorithm, which is popularly used in Laravel.

Verification of Laravel - 哈希 against Hash

You should verify the password against hash to check the string which was used for conversion. For this you can use the check method. This is shown in the code given below −

if (Hash::check(&#39;plain-text&#39;, $hashedLaravel - 哈希)) {
   // The passwords match...
}
登录后复制

Note that the check method compares the plain-text with the hashedLaravel - 哈希 variable and if the result is true, it returns a true value.

以上是Laravel - 哈希的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板