crypto

package
v0.0.0-...-e3e9b0f Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 18 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 GenerateSignatures

func GenerateSignatures(secrets []string, msgID uuid.UUID, currentTime time.Time, inputPayload []byte) ([]string, error)

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

	// BCrypt hashed passwords have a 72 character limit
	MaxPasswordLength = 72
)

Jump to

Keyboard shortcuts

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