Documentation ¶
Overview ¶
Package hashing provides a functionality to hash passwords securely.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckPassword ¶
CheckPassword compares the given password against the stored hash. It returns true, if the password is correct.
Example (CorrectPassword) ¶
Example CorrectPassword shows that the bcrypt hashing algorithm can reliably examine whether a given password matches a hash and thus is correct or not.
// Set a really strong password password := "hello123" // Generate the bcrypt hash for the password hash, err := GenerateHash(password) if err != nil { fmt.Println(err) } // Check that the correct password is recognized // as the correct password correct := CheckPassword(hash, password) fmt.Println(correct)
Output: true
Example (WrongPassword) ¶
Example WrongPassword proves the opposite case passing a wrong password to the CheckPassword function. It is not recognized as correct password and its invalidity is therefore verified.
// Set a really strong password password := "hello123" // Generate the bcrypt hash for the password hash, err := GenerateHash(password) if err != nil { fmt.Println(err) } // Check the password belonging to the hash with // a wrong password and verify its invalidity correct := CheckPassword(hash, "wrong password") fmt.Println(correct)
Output: false
func GenerateHash ¶
GenerateHash returns a bcrypt hash for the given password. Bcrypt is a very secure hashing algorithm for passwords, which also spares the developer from having to generate a salt on his/her own.
Types ¶
This section is empty.