Created
August 26, 2015 00:10
-
-
Save eminetto/6533522d92e1302bfb17 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 ( | |
"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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
have you been able to. produce a$2y$ hash with go?