Documentation ¶
Index ¶
Constants ¶
const DefaultBcryptCost = 10
Variables ¶
This section is empty.
Functions ¶
func GenerateKeyPair ¶ added in v1.2.2
func GenerateKeyPair() (ed25519.PublicKey, ed25519.PrivateKey, error)
Types ¶
type BcryptCrypto ¶
type BcryptCrypto struct {
Cost int
}
BcryptCrypto is the struct that holds the bcrypt crypto methods.
func NewBcryptCrypto ¶
func NewBcryptCrypto(cost int) *BcryptCrypto
NewBcryptCrypto returns a new BcryptCrypto.
func (*BcryptCrypto) Hash ¶
func (b *BcryptCrypto) Hash(password string) ([]byte, error)
Hash hashes a password using the bcrypt algorithm. password is the plaintext password to hash. Returns the hashed password, or an error on failure. The cost is set in the config file.
see: https://godoc.org/golang.org/x/crypto/bcrypt see: utils/config.go for the default cost.
func (*BcryptCrypto) Verify ¶
func (*BcryptCrypto) Verify(password string, hash []byte) (bool, error)
Verify compares a bcrypt hashed password with its possible plaintext equivalent. password is the plaintext password to verify. hash is the bcrypt hashed password. Returns nil on success, or an error on failure. Returns true if the password matches, false if it does not.
type Crypto ¶
type Crypto struct {
Crypto ICrypto
}
Crypto is the struct that holds the crypto methods.
func (Crypto) Hash ¶
Hash hashes a password using the configured crypto method password is the plaintext password to hash. Returns the hashed password, or an error on failure.
type HelperSingleton ¶ added in v1.2.2
type HelperSingleton struct {
// contains filtered or unexported fields
}
HelperSingleton is the struct that holds the crypto helper.
func GetCryptoHelperInstance ¶ added in v1.2.2
func GetCryptoHelperInstance() *HelperSingleton
func (*HelperSingleton) GetCryptoHelper ¶ added in v1.2.2
func (c *HelperSingleton) GetCryptoHelper() Crypto
func (*HelperSingleton) SetCryptoHelper ¶ added in v1.2.2
func (c *HelperSingleton) SetCryptoHelper(crypto ICrypto)
type ICrypto ¶
type ICrypto interface { // Hash hashes a password using the configured crypto method Hash(password string) ([]byte, error) // Verify compares a crypto hashed password with its possible plaintext equivalent Verify(password string, hash []byte) (bool, error) }
ICrypto is the interface for the crypto methods It's used to abstract the crypto methods used in the application so that they can be easily swapped out if needed.