[Laravel5.2 documentation] service-hash

Source: Internet
Author: User
[Laravel5.2 documentation] service-hash 1. Introduction

Laravel's Hash facade provides a secure Bcrypt Hash algorithm for storing user passwords. If you are using the AuthController controller that comes with the Laravel application, this Bcrypt will be automatically used for registration and authentication.

Bcrypt is an excellent choice for hash passwords, because its "working factor" is adjustable, which means that as hardware functions increase, the time required to generate hash will also increase.

2. Basic use

You can call the make method on the Hash facade to Hash the storage password:

 Fill (['password' => Hash: make ($ request-> newPassword)])-> save ();}}

In addition, you can use the global auxiliary function bcrypt:

bcrypt('plain-text');

Verify the hash password

The check method allows you to verify whether the given native string is equal to the given hash. However, if you are using the AuthController provided by Laravel (see the user authentication section for details), you do not need to directly use this method, because the built-in authentication controller automatically calls this method:

If (Hash: check ('plain-text', $ hashedPassword) {// password match ...}

Check if the password needs to be re-hashed

The needsRehash method allows you to determine whether the working factor used by the hash calculator has changed after the last password was hashed:

if (Hash::needsRehash($hashed)) {    $hashed = Hash::make('plain-text');}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.