hasher

package
v0.0.0-...-a510100 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomSalt

func GenerateRandomSalt() []byte

GenerateRandomSalt helper function to generate a random salt

func GenerateRandomSalts

func GenerateRandomSalts(size int) []byte

GenerateRandomSalt helper function to generate a random salt with the specified salt size

func IsAlgorithmAllowed

func IsAlgorithmAllowed(algorithm HashAlgorithm) bool

Types

type HashAlgorithm

type HashAlgorithm string

Defined type for hashing algorithm

const (
	// Hash algorithms
	BCrypt HashAlgorithm = "bcrypt"
	SHA256 HashAlgorithm = "sha256"

	// Default salt size
	DefaultSaltSize = 16
)

type PasswordHasher

type PasswordHasher interface {
	GenerateHashPassword(password []byte, salt []byte) ([]byte, error)
	VerifyPassword(hashedPassword []byte, password []byte, salt []byte) (bool, error)
}

PasswordHasher is the interface for password hasing

type PasswordHasherImpl

type PasswordHasherImpl struct {
	// contains filtered or unexported fields
}

PasswordHasher is the implementation of the PasswordHasher interface

func New

func New(algorithm HashAlgorithm) *PasswordHasherImpl

New create an object of the PasswordHasherImpl

func (PasswordHasherImpl) GenerateHashPassword

func (h PasswordHasherImpl) GenerateHashPassword(password []byte, salt []byte) ([]byte, error)

GenerateHashPassword generate hashed password with the given salt

func (PasswordHasherImpl) VerifyPassword

func (h PasswordHasherImpl) VerifyPassword(hashedPassword []byte, password []byte, salt []byte) (bool, error)

VerifyPassword compare hashed password with the clear password and given salt

Jump to

Keyboard shortcuts

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