From 254366fefbeebcc495645e1d43572411f7336e8a Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Thu, 17 Jan 2019 12:15:31 +0800 Subject: [PATCH] remove magic number and enhance help info for mkpasswd --- .gitignore | 2 +- util/mkpasswd.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6a71502b..8741b35e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,10 +37,10 @@ _testmain.go # bin gnatsd +/util/mkpasswd # coverage coverage.out # Cross compiled binaries pkg - diff --git a/util/mkpasswd.go b/util/mkpasswd.go index 02cdcb51..7751e00b 100644 --- a/util/mkpasswd.go +++ b/util/mkpasswd.go @@ -28,7 +28,8 @@ import ( ) func usage() { - log.Fatalf("Usage: mkpasswd [-p ] [-c COST] \n") + fmt.Printf("Usage: mkpasswd [-p ] [-c COST] \n") + flag.PrintDefaults() } const ( @@ -36,13 +37,13 @@ const ( PasswordLength = 22 // Common advice from the past couple of years suggests that 10 should be sufficient. // Up that a little, to 11. Feel free to raise this higher if this value from 2015 is - // no longer appropriate. Min is 4, Max is 31. + // no longer appropriate. Min is bcrypt.MinCost, Max is bcrypt.MaxCost. DefaultCost = 11 ) func main() { var pw = flag.Bool("p", false, "Input password via stdin") - var cost = flag.Int("c", DefaultCost, "The cost weight, range of 4-31 (11)") + var cost = flag.Int("c", DefaultCost, fmt.Sprintf("The cost weight, range of %d-%d", bcrypt.MinCost, bcrypt.MaxCost)) log.SetFlags(0) flag.Usage = usage