From 36673ae3f066ff0780c12d6adc1aea7dd1720ec6 Mon Sep 17 00:00:00 2001 From: Nicolai Willems <172633+nwillems@users.noreply.github.com> Date: Sun, 24 May 2020 20:55:11 +0200 Subject: [PATCH 1/2] Add helper to do hashing --- cmd/README.md | 6 ++++++ cmd/hasher.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 cmd/README.md create mode 100644 cmd/hasher.go diff --git a/cmd/README.md b/cmd/README.md new file mode 100644 index 00000000..2515a239 --- /dev/null +++ b/cmd/README.md @@ -0,0 +1,6 @@ + +To run the hasher, do like this + +```bash +$ go run hasher.go hunter2 +``` diff --git a/cmd/hasher.go b/cmd/hasher.go new file mode 100644 index 00000000..3669a1b9 --- /dev/null +++ b/cmd/hasher.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "os" + + "golang.org/x/crypto/bcrypt" +) + +func main() { + password := os.Args[1] + + hash, err := bcrypt.GenerateFromPassword([]byte(password), 12) + if err != nil { + fmt.Println("Error generating hash: %s", err) + } + fmt.Println(string(hash)) +} From 076fd65dea918932cb3ffd313635b70772ad3f0c Mon Sep 17 00:00:00 2001 From: Nicolai Willems <172633+nwillems@users.noreply.github.com> Date: Fri, 5 Jun 2020 22:48:33 +0200 Subject: [PATCH 2/2] Use default cost for bcrypt --- cmd/hasher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/hasher.go b/cmd/hasher.go index 3669a1b9..d3c3459f 100644 --- a/cmd/hasher.go +++ b/cmd/hasher.go @@ -10,7 +10,7 @@ import ( func main() { password := os.Args[1] - hash, err := bcrypt.GenerateFromPassword([]byte(password), 12) + hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { fmt.Println("Error generating hash: %s", err) }