crypto

package
v0.0.0-...-12abf9b Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PasswordHashCost = DefaultHashCost

PasswordHashCost is the current pasword hashing cost for all new hashes generated with GenerateHashFromPassword.

Functions

func CompareHashAndPassword

func CompareHashAndPassword(ctx context.Context, hash, password string) error

CompareHashAndPassword compares the hash and password, returns nil if equal otherwise an error. Context can be used to cancel the hashing if the algorithm supports it.

func GenerateFromPassword

func GenerateFromPassword(ctx context.Context, password string) (string, error)

GenerateFromPassword generates a password hash from a password, using PasswordHashCost. Context can be used to cancel the hashing if the algorithm supports it.

func GenerateOtp

func GenerateOtp(digits int) (string, error)

GenerateOtp generates a random n digit otp

func GenerateTokenHash

func GenerateTokenHash(emailOrPhone, otp string) string

func SecureToken

func SecureToken(options ...int) string

SecureToken creates a new random token

Types

type HashCost

type HashCost = int
const (
	// DefaultHashCost represents the default
	// hashing cost for any hashing algorithm.
	DefaultHashCost HashCost = iota

	// QuickHashCosts represents the quickest
	// hashing cost for any hashing algorithm,
	// useful for tests only.
	QuickHashCost HashCost = iota
)

Jump to

Keyboard shortcuts

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