hashers

package
v0.0.0-...-b97e90d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnsablePasswordPrefix is the prefix for an unusable password.
	UnusablePasswordPrefix = "!"

	// HashSeparator is the hash separator.
	HashSeparator = "$"
)

Variables

PasswordHashers are supported password hashers.

Functions

func CheckPassword

func CheckPassword(password string, encoded string) bool

CheckPassword checks if the raw password matches with the encoded one. Returns true if they match. Otherwise false.

func ConstantTimeCompare

func ConstantTimeCompare(val1 string, val2 string) bool

func IsPasswordUsable

func IsPasswordUsable(encoded string) bool

IsPasswordUsable return true the encoded password is usable.

func MakePassword

func MakePassword(password string, salt string, hasher string) (string, error)

MakePassword takes a raw password, a salt and a given hasher (see password hasher algorithm name -- Algorithm() method) then returns this password encoded.

func MaskHash

func MaskHash(hash string, show int, char string) string

func OrderedPasswordHashers

func OrderedPasswordHashers() map[string]PasswordHasher

OrderedPasswordHashers returns password hashers map ordered by their algorithm name.

func RandomString

func RandomString(length int) string

func RandomStringWithChars

func RandomStringWithChars(length int, chars string) string

Types

type MD5PasswordHasher

type MD5PasswordHasher struct{}

MD5PasswordHasher is the MD5 password hasher.

func (*MD5PasswordHasher) Algorithm

func (p *MD5PasswordHasher) Algorithm() string

Algorithm returns the algorithm name of this hasher.

func (*MD5PasswordHasher) Encode

func (p *MD5PasswordHasher) Encode(password string, salt string) string

Encode encodes the given password (adding the given salt) then returns encoded.

func (*MD5PasswordHasher) SafeSummary

func (p *MD5PasswordHasher) SafeSummary(encoded string) PasswordSummary

SafeSummary returns a summary of the encoded password.

func (*MD5PasswordHasher) Salt

func (p *MD5PasswordHasher) Salt() string

Salt returns the default salt (which defaults to a random 12 characters string).

func (*MD5PasswordHasher) Verify

func (p *MD5PasswordHasher) Verify(password string, encoded string) bool

Verify takes the raw password and the encoded one, then checks if they match.

type PBKDF2PasswordHasher

type PBKDF2PasswordHasher struct{}

PBKDF2PasswordHasher is the PBKDF2 SHA1 password hasher.

func (*PBKDF2PasswordHasher) Algorithm

func (p *PBKDF2PasswordHasher) Algorithm() string

Algorithm returns the algorithm name of this hasher.

func (*PBKDF2PasswordHasher) Encode

func (p *PBKDF2PasswordHasher) Encode(password string, salt string) string

Encode encodes the given password (adding the given salt) then returns encoded.

func (*PBKDF2PasswordHasher) EncodeWithIteration

func (p *PBKDF2PasswordHasher) EncodeWithIteration(password string, salt string, iter int) string

EncodeWithIteration encodes the given password (adding the given salt) with iteration then returns encoded.

func (*PBKDF2PasswordHasher) SafeSummary

func (p *PBKDF2PasswordHasher) SafeSummary(encoded string) PasswordSummary

SafeSummary returns a summary of the encoded password.

func (*PBKDF2PasswordHasher) Salt

func (p *PBKDF2PasswordHasher) Salt() string

Salt returns the default salt (which defaults to a random 12 characters string).

func (*PBKDF2PasswordHasher) Verify

func (p *PBKDF2PasswordHasher) Verify(password string, encoded string) bool

Verify takes the raw password and the encoded one, then checks if they match.

type PBKDF2SHA1PasswordHasher

type PBKDF2SHA1PasswordHasher struct{}

PBKDF2SHA1PasswordHasher is the PBKDF2 SHA1 password hasher.

func (*PBKDF2SHA1PasswordHasher) Algorithm

func (p *PBKDF2SHA1PasswordHasher) Algorithm() string

Algorithm returns the algorithm name of this hasher.

func (*PBKDF2SHA1PasswordHasher) Encode

func (p *PBKDF2SHA1PasswordHasher) Encode(password string, salt string) string

Encode encodes the given password (adding the given salt) then returns encoded.

func (*PBKDF2SHA1PasswordHasher) EncodeWithIteration

func (p *PBKDF2SHA1PasswordHasher) EncodeWithIteration(password string, salt string, iter int) string

EncodeWithIteration encodes the given password (adding the given salt) with iteration then returns encoded.

func (*PBKDF2SHA1PasswordHasher) SafeSummary

func (p *PBKDF2SHA1PasswordHasher) SafeSummary(encoded string) PasswordSummary

SafeSummary returns a summary of the encoded password.

func (*PBKDF2SHA1PasswordHasher) Salt

func (p *PBKDF2SHA1PasswordHasher) Salt() string

Salt returns the default salt (which defaults to a random 12 characters string).

func (*PBKDF2SHA1PasswordHasher) Verify

func (p *PBKDF2SHA1PasswordHasher) Verify(password string, encoded string) bool

Verify takes the raw password and the encoded one, then checks if they match.

type PasswordHasher

type PasswordHasher interface {
	Encode(password string, salt string) string
	Verify(password string, encoded string) bool
	SafeSummary(encoded string) PasswordSummary
	Algorithm() string
	Salt() string
}

PasswordHasher is a password hasher.

func IdentityHasher

func IdentityHasher(encoded string) (PasswordHasher, error)

IdentityHasher takes an encoded password and returns its corresponding hasher.

type PasswordSummary

type PasswordSummary struct {
	Algorithm string
	Salt      string
	Hash      string
}

PasswordSummary contains encoded password information.

type SHA1PasswordHasher

type SHA1PasswordHasher struct{}

SHA1PasswordHasher is the SHA1 password hasher.

func (*SHA1PasswordHasher) Algorithm

func (p *SHA1PasswordHasher) Algorithm() string

Algorithm returns the algorithm name of this hasher.

func (*SHA1PasswordHasher) Encode

func (p *SHA1PasswordHasher) Encode(password string, salt string) string

Encode encodes the given password (adding the given salt) then returns encoded.

func (*SHA1PasswordHasher) SafeSummary

func (p *SHA1PasswordHasher) SafeSummary(encoded string) PasswordSummary

SafeSummary returns a summary of the encoded password.

func (*SHA1PasswordHasher) Salt

func (p *SHA1PasswordHasher) Salt() string

Salt returns the default salt (which defaults to a random 12 characters string).

func (*SHA1PasswordHasher) Verify

func (p *SHA1PasswordHasher) Verify(password string, encoded string) bool

Verify takes the raw password and the encoded one, then checks if they match.

Jump to

Keyboard shortcuts

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