GoravelGoravel
Home
Video
  • English
  • 简体中文
GitHub
Home
Video
  • English
  • 简体中文
GitHub
  • Prologue

    • Upgrade Guide

      • Upgrading To v1.15 From v1.14
      • Upgrading To v1.14 From v1.13
      • History Upgrade
    • Contribution Guide
    • Excellent Extend Packages
  • Getting Started

    • Installation
    • Configuration
    • Directory Structure
    • Compile
  • Architecture Concepts

    • Request Lifecycle
    • Service Container
    • Service Providers
    • Facades
  • The Basics

    • Routing
    • HTTP Middleware
    • Controllers
    • Requests
    • Responses
    • Views
    • Grpc
    • Session
    • Validation
    • Logging
  • Digging Deeper

    • Artisan Console
    • Cache
    • Events
    • File Storage
    • Mail
    • Queues
    • Task Scheduling
    • Localization
    • Package Development
    • Color
    • Strings
    • Helpers
  • Security

    • Authentication
    • Authorization
    • Encryption
    • Hashing
  • ORM

    • Getting Started
    • Relationships
    • Migrations
    • Seeding
    • Factories
  • Testing

    • Getting Started
    • HTTP Tests
    • Mock

Hashing

  • Introduction
  • Configuration
  • Basic Usage
    • Hashing Passwords
    • Verifying That A Password Matches A Hash
    • Determining If A Password Needs To Be Rehashed

Introduction

The Goravel facades.Hash() provides secure Argon2id and Bcrypt hashing for storing user passwords. If you are using one of the Goravel application starter kits, Argon2id will be used for registration and authentication by default.

Configuration

The default hashing driver for your application is configured in your application's config/hashing.go configuration file. There are currently several supported drivers: Argon2id and Bcrypt.

Basic Usage

Hashing Passwords

You may hash a password by calling the Make method on the facades.Hash():

password, err := facades.Hash().Make(password)

Verifying That A Password Matches A Hash

The Check method provided by the Hash facade allows you to verify that a given plain-text string corresponds to a given hash:

if facades.Hash().Check('plain-text', hashedPassword) {
    // The passwords match...
}

Determining If A Password Needs To Be Rehashed

The NeedsRehash method provided by the Hash facade allows you to determine if the work factor used by the hasher has changed since the password was hashed. Some applications choose to perform this check during the application's authentication process:

if facades.Hash().NeedsRehash(hashed) {
     hashed = facades.Hash().Make('plain-text');
}
Edit this page
Prev
Encryption