cred

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MagicPrefix   = "$6$"
	RandomSalt    = ""
	RoundsDefault = 5000
	RoundsMax     = 999999999
	RoundsMin     = 1000
	SaltLenMax    = 16
	SaltLenMin    = 1
)
View Source
const Hash64Chars = "./0123456789" +
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
	"abcdefghijklmnopqrstuvwxyz"

Variables

This section is empty.

Functions

func Crypt added in v1.0.7

func Crypt(keystr, saltstr string) string

Crypt takes key and salt strings and performs the SHA512-crypt hashing algorithm on them, returning a full hash string suitable for storage and later password verification.

If the salt string is the value RandomSalt, a randomly-generated salt parameter string will be generated with a length of SaltLenMax and RoundsDefault number of rounds.

func GenerateSalt added in v1.0.7

func GenerateSalt(length, rounds int) string

GenerateSalt creates a random salt parameter string with the random bytes being of the length provided, and the rounds parameter set as specified.

If the length is greater than SaltLenMax, a string of that length will be returned instead. Similarly, if length is less than SaltLenMin, a string of that length will be returned instead.

If rounds is equal to RoundsDefault, then the 'rounds=' part of the salt parameter string is elided.

func Hash64 added in v1.0.7

func Hash64(src []byte) (hash []byte)

Hash64 is a variant of Base64 encoding. It is commonly used with password hashing algorithms to encode the result of their checksum output.

The algorithm operates on up to 3 bytes at a time, encoding the following 6-bit sequences into up to 4 hash64 ASCII bytes.

  1. Bottom 6 bits of the first byte
  2. Top 2 bits of the first byte, and bottom 4 bits of the second byte.
  3. Top 4 bits of the second byte, and bottom 2 bits of the third byte.
  4. Top 6 bits of the third byte.

This encoding method does not emit padding bytes as Base64 does.

func Verify added in v1.0.7

func Verify(key, hash string) bool

Verify hashes a key using the same salt parameters as the given hash string, and if the results match, it returns true.

Types

type Argon2idCredManager

type Argon2idCredManager struct{}

func NewArgon2idCredManager

func NewArgon2idCredManager() *Argon2idCredManager

func (*Argon2idCredManager) GetHashedPassword

func (cm *Argon2idCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Argon2idCredManager) IsPasswordCorrect

func (cm *Argon2idCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type BcryptCredManager

type BcryptCredManager struct{}

func NewBcryptCredManager

func NewBcryptCredManager() *BcryptCredManager

func (*BcryptCredManager) GetHashedPassword

func (cm *BcryptCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*BcryptCredManager) IsPasswordCorrect

func (cm *BcryptCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type CredManager

type CredManager interface {
	GetHashedPassword(password string, userSalt string, organizationSalt string) string
	IsPasswordCorrect(password string, passwordHash string, userSalt string, organizationSalt string) bool
}

func GetCredManager

func GetCredManager(passwordType string) CredManager

type Md5UserSaltCredManager

type Md5UserSaltCredManager struct{}

func NewMd5UserSaltCredManager

func NewMd5UserSaltCredManager() *Md5UserSaltCredManager

func (*Md5UserSaltCredManager) GetHashedPassword

func (cm *Md5UserSaltCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Md5UserSaltCredManager) IsPasswordCorrect

func (cm *Md5UserSaltCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type Pbkdf2SaltCredManager

type Pbkdf2SaltCredManager struct{}

func NewPbkdf2SaltCredManager

func NewPbkdf2SaltCredManager() *Pbkdf2SaltCredManager

func (*Pbkdf2SaltCredManager) GetHashedPassword

func (cm *Pbkdf2SaltCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Pbkdf2SaltCredManager) IsPasswordCorrect

func (cm *Pbkdf2SaltCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type PlainCredManager

type PlainCredManager struct{}

func NewPlainCredManager

func NewPlainCredManager() *PlainCredManager

func (*PlainCredManager) GetHashedPassword

func (cm *PlainCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*PlainCredManager) IsPasswordCorrect

func (cm *PlainCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type Sha256SaltCredManager

type Sha256SaltCredManager struct{}

func NewSha256SaltCredManager

func NewSha256SaltCredManager() *Sha256SaltCredManager

func (*Sha256SaltCredManager) GetHashedPassword

func (cm *Sha256SaltCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Sha256SaltCredManager) IsPasswordCorrect

func (cm *Sha256SaltCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type Sha512CryptCredManager added in v1.0.7

type Sha512CryptCredManager struct{}

func NewSha512CryptCredManager added in v1.0.7

func NewSha512CryptCredManager() *Sha512CryptCredManager

func (*Sha512CryptCredManager) GetHashedPassword added in v1.0.7

func (cm *Sha512CryptCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Sha512CryptCredManager) IsPasswordCorrect added in v1.0.7

func (cm *Sha512CryptCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

type Sha512SaltCredManager

type Sha512SaltCredManager struct{}

func NewSha512SaltCredManager

func NewSha512SaltCredManager() *Sha512SaltCredManager

func (*Sha512SaltCredManager) GetHashedPassword

func (cm *Sha512SaltCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string

func (*Sha512SaltCredManager) IsPasswordCorrect

func (cm *Sha512SaltCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool

Jump to

Keyboard shortcuts

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