Documentation ¶
Index ¶
- Constants
- Variables
- func CheckPassword(password string, encoded string) bool
- func ConstantTimeCompare(val1 string, val2 string) bool
- func IsPasswordUsable(encoded string) bool
- func MakePassword(password string, salt string, hasher string) (string, error)
- func MaskHash(hash string, show int, char string) string
- func OrderedPasswordHashers() map[string]PasswordHasher
- func RandomString(length int) string
- func RandomStringWithChars(length int, chars string) string
- type MD5PasswordHasher
- func (p *MD5PasswordHasher) Algorithm() string
- func (p *MD5PasswordHasher) Encode(password string, salt string) string
- func (p *MD5PasswordHasher) SafeSummary(encoded string) PasswordSummary
- func (p *MD5PasswordHasher) Salt() string
- func (p *MD5PasswordHasher) Verify(password string, encoded string) bool
- type PBKDF2PasswordHasher
- func (p *PBKDF2PasswordHasher) Algorithm() string
- func (p *PBKDF2PasswordHasher) Encode(password string, salt string) string
- func (p *PBKDF2PasswordHasher) EncodeWithIteration(password string, salt string, iter int) string
- func (p *PBKDF2PasswordHasher) SafeSummary(encoded string) PasswordSummary
- func (p *PBKDF2PasswordHasher) Salt() string
- func (p *PBKDF2PasswordHasher) Verify(password string, encoded string) bool
- type PBKDF2SHA1PasswordHasher
- func (p *PBKDF2SHA1PasswordHasher) Algorithm() string
- func (p *PBKDF2SHA1PasswordHasher) Encode(password string, salt string) string
- func (p *PBKDF2SHA1PasswordHasher) EncodeWithIteration(password string, salt string, iter int) string
- func (p *PBKDF2SHA1PasswordHasher) SafeSummary(encoded string) PasswordSummary
- func (p *PBKDF2SHA1PasswordHasher) Salt() string
- func (p *PBKDF2SHA1PasswordHasher) Verify(password string, encoded string) bool
- type PasswordHasher
- type PasswordSummary
- type SHA1PasswordHasher
- func (p *SHA1PasswordHasher) Algorithm() string
- func (p *SHA1PasswordHasher) Encode(password string, salt string) string
- func (p *SHA1PasswordHasher) SafeSummary(encoded string) PasswordSummary
- func (p *SHA1PasswordHasher) Salt() string
- func (p *SHA1PasswordHasher) Verify(password string, encoded string) bool
Constants ¶
const ( // UnsablePasswordPrefix is the prefix for an unusable password. UnusablePasswordPrefix = "!" // HashSeparator is the hash separator. HashSeparator = "$" )
Variables ¶
var PasswordHashers = []PasswordHasher{ &MD5PasswordHasher{}, &SHA1PasswordHasher{}, &PBKDF2PasswordHasher{}, &PBKDF2SHA1PasswordHasher{}, }
PasswordHashers are supported password hashers.
Functions ¶
func CheckPassword ¶
CheckPassword checks if the raw password matches with the encoded one. Returns true if they match. Otherwise false.
func ConstantTimeCompare ¶
func IsPasswordUsable ¶
IsPasswordUsable return true the encoded password is usable.
func MakePassword ¶
MakePassword takes a raw password, a salt and a given hasher (see password hasher algorithm name -- Algorithm() method) then returns this password encoded.
func OrderedPasswordHashers ¶
func OrderedPasswordHashers() map[string]PasswordHasher
OrderedPasswordHashers returns password hashers map ordered by their algorithm name.
func RandomString ¶
func RandomStringWithChars ¶
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).
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).
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).
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 ¶
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).