Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created August 26, 2015 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eminetto/6533522d92e1302bfb17 to your computer and use it in GitHub Desktop.
Save eminetto/6533522d92e1302bfb17 to your computer and use it in GitHub Desktop.
package main
import (
"golang.org/x/crypto/bcrypt"
"fmt"
)
func main() {
password := []byte("MyDarkSecret")
hashedPasswordFromPHP := []byte("$2y$10$zlo5xhAXy5oyfjQPykUHP.tcnxdJmKHNBWgOssYKIcPm4iyHRe/1e");
// Hashing the password with the cost of 10
hashedPassword, err := bcrypt.GenerateFromPassword(password, 10)
if err != nil {
panic(err)
}
fmt.Println(string(hashedPassword))
// Comparing the password with the hash
err = bcrypt.CompareHashAndPassword(hashedPassword, password)
fmt.Println(err) // nil means it is a match
// Comparing the password with the hash generated in PHP
err = bcrypt.CompareHashAndPassword(hashedPasswordFromPHP, password)
fmt.Println(err) // nil means it is a match
}
@meshenka
Copy link

have you been able to. produce a $2y$ hash with go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment