Created
February 2, 2017 15:32
-
-
Save mascii/7846d49fe1e195a2a5e035f442373ff0 to your computer and use it in GitHub Desktop.
password_hash function
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("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
http://stackoverflow.com/questions/23259586/bcrypt-password-hashing-in-golang-compatible-with-node-js