Created
October 22, 2017 19:14
-
-
Save bussiere/bbb5894324b921d48fe44a26ce73e96a to your computer and use it in GitHub Desktop.
passwird hashing in go
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("#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