Documentation ¶
Overview ¶
Package passlock stores your passwords a tiny bit more safely than bcrypt alone.
Example ¶
// Your plaintext password password := []byte("password") // Get a key key := NewEncryptionKey() // Store the password encryptedPassword, err := GenerateFromPassword(password, DefaultCost, key) if err != nil { fmt.Println(err) } // Retrieve the password err = CompareHashAndPassword(encryptedPassword, password, key) if err != nil { fmt.Println(err) return } // We're going to rotate keys -- let's start by making a new key newKey := NewEncryptionKey() // Rotate the keys newEncryptedPassword, err := RotateKey(key, newKey, encryptedPassword) if err != nil { fmt.Println(err) return } // See if that password matches with the new key err = CompareHashAndPassword(newEncryptedPassword, password, newKey) if err != nil { fmt.Println(err) return } fmt.Println("Passwords matched!")
Output: Passwords matched!
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultCost = 14
DefaultCost is the minimum work factor for bcrypt.
Variables ¶
This section is empty.
Functions ¶
func CompareHashAndPassword ¶
CompareHashAndPassword compares a hashed password to a plaintext password. It will return nil if the passwords match, and an error otherwise.
This package wraps all the errors exported by the bcrypt package, so you won't need to import that package to compare errors.
func GenerateFromPassword ¶
GenerateFromPassword hashes and salts a password from the given plaintext password and HMAC key.
func NewEncryptionKey ¶
func NewEncryptionKey() *[32]byte
NewEncryptionKey generates a random 256-bit key for Encrypt() and Decrypt(). It panics if the source of randomness fails.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.