File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -378,7 +378,12 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
378378 password := getParam (flags , "password" )
379379
380380 if password == "" {
381- password , err = users .HashPwd ("admin" )
381+ pwd , err := users .RandomPwd ()
382+ checkErr (err )
383+
384+ log .Println ("Generated random admin password for quick setup:" , pwd )
385+
386+ password , err = users .HashPwd (pwd )
382387 checkErr (err )
383388 }
384389
Original file line number Diff line number Diff line change 11package users
22
33import (
4+ "crypto/rand"
5+ "encoding/base64"
46 "golang.org/x/crypto/bcrypt"
57)
68
9+ // randomPasswordBytesCount is chosen to fit in a base64 string without padding
10+ const randomPasswordBytesCount = 9
11+
712// HashPwd hashes a password.
813func HashPwd (password string ) (string , error ) {
914 bytes , err := bcrypt .GenerateFromPassword ([]byte (password ), bcrypt .DefaultCost )
@@ -15,3 +20,15 @@ func CheckPwd(password, hash string) bool {
1520 err := bcrypt .CompareHashAndPassword ([]byte (hash ), []byte (password ))
1621 return err == nil
1722}
23+
24+ func RandomPwd () (string , error ) {
25+ randomPasswordBytes := make ([]byte , randomPasswordBytesCount )
26+ var _ , err = rand .Read (randomPasswordBytes )
27+ if err != nil {
28+ return "" , err
29+ }
30+
31+ // This is done purely to make the password human-readable
32+ var randomPasswordString = base64 .URLEncoding .EncodeToString (randomPasswordBytes )
33+ return randomPasswordString , nil
34+ }
You can’t perform that action at this time.
0 commit comments