token

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: MIT Imports: 2 Imported by: 0

README

token

Creates a token hash and verifies that a token matches a key and a cost.

How to use

Hash()

Creates a token hash using a strong one-way hashing algorithm (bcrypt).

Parameters
  • key (string) - a key
  • cost (integer) - which denotes the algorithmic cost that should be used
Example
import "github.com/martinusso/token"

token := token.Hash("123", 10)
fmt.Println(token)

The above example will optput something similar to:

JDJhJDEwJDY1L3QwVFIyeFBMOWlNZWxxbWtzRU9HWUJ5MXZoajg2NExOU0FNTVZUQjEzR3dndjExTlYy
Verify()

Verifies that a token hash matches a key and cost.

Parameters
  • key (string) - a key
  • cost (integer) - which denotes the algorithmic cost that should be used
  • hash (string) - a token hash created by Hash method
Example
hash := "JDJhJDEwJDY1L3QwVFIyeFBMOWlNZWxxbWtzRU9HWUJ5MXZoajg2NExOU0FNTVZUQjEzR3dndjExTlYy"
fmt.Println(Verify("123", 10, hash))

The above example will output true.

Documentation

Index

Constants

View Source
const (
	MinCost int = 10 // the minimum allowable cost as passed in to Hash
	MaxCost int = 31 // the maximum allowable cost as passed in to Hash
)

Variables

This section is empty.

Functions

func Hash

func Hash(key string, cost int) string

Token creates a token hash key (string) - a key cost (int) - which denotes the algorithmic cost that should be used

func Verify

func Verify(key string, cost int, hash string) bool

Verify verifies that a token hash matches a key and cost key (string) - a key cost (int) - which denotes the algorithmic cost that should be used hash (string) - a token hash created by Hash

Types

This section is empty.

Jump to

Keyboard shortcuts

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