forked from drew/smtprelay
hasher: Check number of arguments
This makes for a better user experience than a go segfault.
This commit is contained in:
@@ -8,11 +8,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
fmt.Fprintln(os.Stderr, "Usage: hasher PASSWORD")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
password := os.Args[1]
|
password := os.Args[1]
|
||||||
|
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error generating hash: %s", err)
|
fmt.Fprintln(os.Stderr, "Error generating hash: %s", err)
|
||||||
}
|
}
|
||||||
fmt.Println(string(hash))
|
fmt.Println(string(hash))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user