hashing

package
v0.0.0-...-51710b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package hashing provides a functionality to hash passwords securely.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash string, password string) bool

CheckPassword compares the given password against the stored hash. It returns true, if the password is correct.

Example (CorrectPassword)

Example CorrectPassword shows that the bcrypt hashing algorithm can reliably examine whether a given password matches a hash and thus is correct or not.

// Set a really strong password
password := "hello123"

// Generate the bcrypt hash for the password
hash, err := GenerateHash(password)
if err != nil {
	fmt.Println(err)
}

// Check that the correct password is recognized
// as the correct password
correct := CheckPassword(hash, password)

fmt.Println(correct)
Output:

true
Example (WrongPassword)

Example WrongPassword proves the opposite case passing a wrong password to the CheckPassword function. It is not recognized as correct password and its invalidity is therefore verified.

// Set a really strong password
password := "hello123"

// Generate the bcrypt hash for the password
hash, err := GenerateHash(password)
if err != nil {
	fmt.Println(err)
}

// Check the password belonging to the hash with
// a wrong password and verify its invalidity
correct := CheckPassword(hash, "wrong password")

fmt.Println(correct)
Output:

false

func GenerateHash

func GenerateHash(password string) (string, error)

GenerateHash returns a bcrypt hash for the given password. Bcrypt is a very secure hashing algorithm for passwords, which also spares the developer from having to generate a salt on his/her own.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL