Added password generation and hashing helper
This commit is contained in:
@@ -28,15 +28,48 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
pwgen "github.com/sethvargo/go-password/password"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/net/webdav"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var configFile = flag.String("config", "sharedav.toml", "Config file to be used.")
|
||||
var genPassword = flag.Bool("genpass", false, "If set, a password will be generated and hashed.")
|
||||
var hashPassword = flag.String("hashpass", "", "If set, the given password will be hashed.")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *genPassword {
|
||||
// math.rand is not secure. For determining the number of digits in a password
|
||||
// it should suffice, though.
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
pwLen := 32
|
||||
pw, err := pwgen.Generate(pwLen, rand.Intn(pwLen/2), 0, false, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(pw), 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Password: %s\n", pw)
|
||||
fmt.Printf(" Hash: %s\n", hash)
|
||||
return
|
||||
} else if *hashPassword != "" {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(*hashPassword), 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(string(hash))
|
||||
return
|
||||
}
|
||||
|
||||
c := LoadConfig(*configFile)
|
||||
|
||||
h := &webdav.Handler{}
|
||||
|
||||
Reference in New Issue
Block a user