Last active
August 5, 2016 20:36
-
-
Save apg/3dfe5af54a927593ad64fb815585ff8d to your computer and use it in GitHub Desktop.
Simple tool to get a bcrypt hash with a given cost. `go run bcrypt.go -password foobar -cost 20`
This file contains hidden or 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 ( | |
"flag" | |
"fmt" | |
"os" | |
"golang.org/x/crypto/bcrypt" | |
) | |
var password = flag.String("password", "", "password to hash") | |
var hash = flag.String("hash", "", "hash to compare to") | |
var cost = flag.Int("cost", 10, "password cost") | |
func main() { | |
flag.Parse() | |
if *hash == "" { | |
h, e := bcrypt.GenerateFromPassword([]byte(*password), *cost) | |
if e != nil { | |
fmt.Println("ERR", e) | |
os.Exit(1) | |
} | |
fmt.Println("hash: ", string(h)) | |
} else { | |
e := bcrypt.CompareHashAndPassword([]byte(*hash), []byte(*password)) | |
if e != nil { | |
fmt.Println("ERR", e) | |
os.Exit(1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment