Skip to content

Instantly share code, notes, and snippets.

@bussiere
Created October 22, 2017 19:14
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 bussiere/bbb5894324b921d48fe44a26ce73e96a to your computer and use it in GitHub Desktop.
Save bussiere/bbb5894324b921d48fe44a26ce73e96a to your computer and use it in GitHub Desktop.
passwird hashing in go
package main
import (
"golang.org/x/crypto/bcrypt"
"fmt"
)
func main() {
password := []byte("#toto1515Grandia")
// Hashing the password with the default cost of 10
hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
if err != nil {
panic(err)
}
var pass = []byte("$2a$08$KsnR4mA3TcEiEq.lNT3K6eYgIrFBpKxfPIN.GNjAdflpMcD90jPRG")
fmt.Println(string(hashedPassword))
fmt.Println("$2a$08$KsnR4mA3TcEiEq.lNT3K6eYgIrFBpKxfPIN.GNjAdflpMcD90jPRG")
// Comparing the password with the hash
err = bcrypt.CompareHashAndPassword(pass, 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