password

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes against the current preferred hasher.

func VerifyPassword

func VerifyPassword(password, hashedPassword string) (valid, stale bool)

VerifyPassword verifies an entered password against a hashed password and returns whether the hash is "stale" (i.e., was verified using the FIRST preferred hasher above).

Types

type BcryptPasswordHasher

type BcryptPasswordHasher struct {
	Cost int
}

BcryptPasswordHasher handles password hashing with Bcrypt. Create with `0` as the work factor to default to bcrypt.DefaultCost at hashing time. The Cost field represents work factor.

func (BcryptPasswordHasher) HashPassword

func (h BcryptPasswordHasher) HashPassword(password string) (string, error)

HashPassword creates a one-way digest ("hash") of a password. In the case of Bcrypt, a pseudorandom salt is included automatically by the underlying library. For security reasons, the work factor is always at _least_ bcrypt.DefaultCost.

func (BcryptPasswordHasher) VerifyPassword

func (h BcryptPasswordHasher) VerifyPassword(password, hashedPassword string) bool

VerifyPassword validates whether a one-way digest ("hash") of a password was created from a given plaintext password.

type DummyPasswordHasher

type DummyPasswordHasher struct{}

DummyPasswordHasher is for testing ONLY. DO NOT USE in a production context.

func (DummyPasswordHasher) HashPassword

func (h DummyPasswordHasher) HashPassword(password string) (string, error)

HashPassword creates a one-way digest ("hash") of a password. In the case of Bcrypt, a pseudorandom salt is included automatically by the underlying library.

func (DummyPasswordHasher) VerifyPassword

func (h DummyPasswordHasher) VerifyPassword(password, hashedPassword string) bool

VerifyPassword validates whether a one-way digest ("hash") of a password was created from a given plaintext password.

type PasswordHasher

type PasswordHasher interface {
	HashPassword(string) (string, error)
	VerifyPassword(string, string) bool
}

PasswordHasher is an interface type to declare a general-purpose password management tool.

Jump to

Keyboard shortcuts

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