Laravel - 哈希

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

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 theHashfacade which provides a secure way for storing passwords in a hashed manner.

Basic Usage

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

Laravel - 哈希

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

user()->fill([ 'password' => Hash::make($request->newLaravel - 哈希) // Hashing passwords ])->save(); } }
登录后复制

The hashed passwords are stored usingmakemethod. This method allows managing the work factor of thebcrypthashing 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 thecheckmethod. This is shown in the code given below −

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

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

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

相关标签:
来源:php
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!