Skip to content

Instantly share code, notes, and snippets.

@yoppi
Created June 23, 2015 11:47
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 yoppi/06218b367804e0b34172 to your computer and use it in GitHub Desktop.
Save yoppi/06218b367804e0b34172 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
const (
password = "hello"
fail = "helloo"
)
func main() {
hash, err := bcrypt.GenerateFromPassword([]byte(password), 1)
if err != nil {
panic(err)
}
fmt.Printf("%x\n", hash)
err = bcrypt.CompareHashAndPassword(hash, []byte(fail))
if err != nil {
fmt.Printf("bcrypt.Err: %p %#v\n", bcrypt.ErrMismatchedHashAndPassword, bcrypt.ErrMismatchedHashAndPassword)
fmt.Printf("err: %p %#v\n", err, err)
}
}
> ./bcrypt
243261243130244f4954376a3732346a4635334a5a467932646d42794f5478734430374f7037765562396e64765772675769306931736b3237645661
bcrypt.Err: 0x2081f22b0 &errors.errorString{s:"crypto/bcrypt: hashedPassword is not the hash of the given password"}
err: 0x2081f22b0 &errors.errorString{s:"crypto/bcrypt: hashedPassword is not the hash of the given password"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment