Skip to content

Instantly share code, notes, and snippets.

@mascii
Created February 2, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mascii/7846d49fe1e195a2a5e035f442373ff0 to your computer and use it in GitHub Desktop.
Save mascii/7846d49fe1e195a2a5e035f442373ff0 to your computer and use it in GitHub Desktop.
password_hash function
package main
import (
"golang.org/x/crypto/bcrypt"
"fmt"
)
func main() {
password := []byte("pasuwa-do")
// Hashing the password with the cost of 11
hashedPassword, err := bcrypt.GenerateFromPassword(password, 11)
if err != nil {
panic(err)
}
fmt.Println(string(hashedPassword))
hashedPasswordString := []byte("$2a$11$6FhAQrEY2qLVl6r1Bi8kvu.nS8cPARDU2htIg559XYLQc3jRb0gqW")
// Comparing the password with the hash
//err = bcrypt.CompareHashAndPassword(hashedPassword, password)
err = bcrypt.CompareHashAndPassword(hashedPasswordString, password)
fmt.Println(err) // nil means it is a match
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment