[Laravel 5.2 Document] service--Hash

Source: Internet
Author: User

1. Introduction

Laravel's hash façade provides a secure bcrypt hashing algorithm for storing user passwords. If you are using the Laravel app's own Authcontroller controller, the Bcrypt will be automatically used for registration and authentication.

Bcrypt is a great choice for hashing passwords because the "working factor" is adjustable, which means that the time it takes to generate a hash increases as the hardware function increases.

2. Basic use

You can call the Make method hash store password on the hash façade:

 
  Fill ([            ' Password ' = hash::make ($request->newpassword)        ])->save ();}    }

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

Bcrypt (' Plain-text ');

Verify Hash password

The check method allows you to verify that a given native string and a given hash are equal, however, if you are using Laravel's own Authcontroller (see the User authentication section), you do not need to use this method directly because the self-brought authentication controller automatically calls the method:

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

Check if password needs to be re-hashed

The Needsrehash method allows you to determine whether the work factor used by the hash evaluator has changed since 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.