From a2742dff1648c87f76bdbffb06206213a4a6f0fb Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 6 Jan 2019 17:53:47 +0000 Subject: [PATCH 1/2] feat: add hash command License: MIT Signed-off-by: Henrique Dias --- cmd/hash.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cmd/hash.go diff --git a/cmd/hash.go b/cmd/hash.go new file mode 100644 index 00000000..e92203e4 --- /dev/null +++ b/cmd/hash.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "fmt" + + "github.com/filebrowser/filebrowser/v2/users" + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(hashCmd) +} + +var hashCmd = &cobra.Command{ + Use: "hash ", + Short: "Hashes a password", + Long: `Hashes a password using bcrypt algorithm.`, + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + pwd, err := users.HashPwd(args[0]) + checkErr(err) + fmt.Println(pwd) + }, +} From 550269d2edcd0d178d387829e332defd1a68bf42 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 6 Jan 2019 17:55:47 +0000 Subject: [PATCH 2/2] feat: only hash if it's default pw License: MIT Signed-off-by: Henrique Dias --- cmd/root.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 905079b7..e31f635f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -43,7 +43,7 @@ func init() { vaddP(f, "scope", "s", ".", "scope to prepend to a user's scope when it is relative") vaddP(f, "baseurl", "b", "", "base url") vadd(f, "username", "admin", "username for the first user when using quick config") - vadd(f, "password", "admin", "password for the first user when using quick config") + vadd(f, "password", "", "hashed password for the first user when using quick config (default \"admin\")") if err := v.BindPFlags(f); err != nil { panic(err) @@ -197,13 +197,16 @@ func quickSetup(cmd *cobra.Command) { username := v.GetString("username") password := v.GetString("password") + + if password == "" { + password, err = users.HashPwd("admin") + checkErr(err) + } + if username == "" || password == "" { checkErr(errors.New("username and password cannot be empty during quick setup")) } - password, err = users.HashPwd(password) - checkErr(err) - user := &users.User{ Username: username, Password: password,