argon2

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Argon2

An Argon2 hash encoder and decoder for Go with sql.Scanner and driver.Valuer implemented.

  • Implemented sql.Sanner and driver.Valuer to read to and write from SQL databases.

Usage

go get github.com/merajsahebdar/argon2
type User struct {
    ID       uint64
    Password argon2.Argon2
}

func (e User) IsPasswordCorrect(toCompare string) bool {
    if err := e.Password.Compare(toCompare); err != nil {
        return false
    }

    return true
}

func NewUser() *User {
    return &User{
        ID:       1,
        Password: argon2.MustNew(),
    }
}

License

This module is licensed under Apache 2.0 as found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidEncodedHash is returned when the encoded hash is in an invalid format.
	ErrInvalidEncodedHash = errors.New("the encoded hash is not in the correct format")

	// ErrIncompatibleVersion is returned when the encoded hash generated
	// using a different version of argon2.
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")

	// ErrScan is returned when the given value to scanner cannot be represented as a ULID.
	ErrScan = errors.New("cannot scan the given value")

	// ErrMismatched is returned when the given value to compare is not the same as the current hashed value.
	ErrMismatched = errors.New("the given value is not the same as the current hashed value")
)

Functions

func Bytes

func Bytes(n uint32) ([]byte, error)

Bytes generates random bytes of the given size.

Types

type Argon2

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

Argon2 provides Argon2 based hashing operations.

func MustNew

func MustNew(toHash string) Argon2

MustNew forces argon2.New.

func New

func New(toHash string) (Argon2, error)

New returns a new argon2.Argon2 by hashing the given string.

func NewByEncoded

func NewByEncoded(encoded string) (Argon2, error)

NewByEncoded returns a new argon2.Argon2 by decoding the given previously encoded hash.

func (Argon2) Compare

func (a Argon2) Compare(toCompare string) error

Compare compares the current hashed value with the given one.

func (*Argon2) Scan

func (a *Argon2) Scan(src interface{}) error

Scan implements sql.Scanner.

func (Argon2) String

func (a Argon2) String() string

Encode returns an encoded value of the hash.

func (Argon2) Value

func (a Argon2) Value() (driver.Value, error)

Value implements driver.Valuer.

Jump to

Keyboard shortcuts

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