Merge pull request #610 from filebrowser/hashedpwd

feat: require hashed password and add hash command
Former-commit-id: b8d4bd7c9fbdde724beb62c77cee1daba15d315b [formerly fadf295f423c8979fcf7a704b05cffc3a0735d2a] [formerly e4a9044cd0a94b4f4fa1a8f441c563fe0a564a62 [formerly a2d32438f1]]
Former-commit-id: fbf8a1d1e85646a43bf220f1bb73d40481da7df0 [formerly a5b48143fb9c39da6b1b8f43c1e80729892a1837]
Former-commit-id: 5ba56215decd17c9c2b8cd59546a7181cef96aea
pull/726/head
Henrique Dias 2019-01-06 18:25:09 +00:00 committed by GitHub
commit f70fc2d954
2 changed files with 31 additions and 4 deletions

24
cmd/hash.go Normal file
View File

@ -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 <password>",
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)
},
}

View File

@ -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,