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) {
378
378
password := getParam (flags , "password" )
379
379
380
380
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 )
382
387
checkErr (err )
383
388
}
384
389
Original file line number Diff line number Diff line change 1
1
package users
2
2
3
3
import (
4
+ "crypto/rand"
5
+ "encoding/base64"
4
6
"golang.org/x/crypto/bcrypt"
5
7
)
6
8
9
+ // randomPasswordBytesCount is chosen to fit in a base64 string without padding
10
+ const randomPasswordBytesCount = 9
11
+
7
12
// HashPwd hashes a password.
8
13
func HashPwd (password string ) (string , error ) {
9
14
bytes , err := bcrypt .GenerateFromPassword ([]byte (password ), bcrypt .DefaultCost )
@@ -15,3 +20,15 @@ func CheckPwd(password, hash string) bool {
15
20
err := bcrypt .CompareHashAndPassword ([]byte (hash ), []byte (password ))
16
21
return err == nil
17
22
}
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