Created
June 23, 2015 11:47
-
-
Save yoppi/06218b367804e0b34172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ./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