|
1 | | -// Copyright (c) 2020 The Decred developers |
| 1 | +// Copyright (c) 2020-2021 The Decred developers |
2 | 2 | // Use of this source code is governed by an ISC |
3 | 3 | // license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | package main |
6 | 6 |
|
7 | 7 | import ( |
8 | 8 | "context" |
| 9 | + "crypto/sha256" |
9 | 10 | "errors" |
10 | 11 | "fmt" |
11 | 12 | "os" |
@@ -51,6 +52,19 @@ func run(ctx context.Context) error { |
51 | 52 | return err |
52 | 53 | } |
53 | 54 |
|
| 55 | + // Request admin password if admin password is not set in config. |
| 56 | + var adminAuthSHA [32]byte |
| 57 | + if cfg.AdminPass == "" { |
| 58 | + adminAuthSHA, err = passwordHashPrompt(ctx, "Admin password for accessing admin page: ") |
| 59 | + if err != nil { |
| 60 | + return fmt.Errorf("cannot use password: %v", err) |
| 61 | + } |
| 62 | + } else { |
| 63 | + adminAuthSHA = sha256.Sum256([]byte(cfg.AdminPass)) |
| 64 | + // Clear password string |
| 65 | + cfg.AdminPass = "" |
| 66 | + } |
| 67 | + |
54 | 68 | // Show version at startup. |
55 | 69 | log.Infof("Version %s (Go version %s %s/%s)", version.String(), runtime.Version(), |
56 | 70 | runtime.GOOS, runtime.GOARCH) |
@@ -98,7 +112,7 @@ func run(ctx context.Context) error { |
98 | 112 | SupportEmail: cfg.SupportEmail, |
99 | 113 | VspClosed: cfg.VspClosed, |
100 | 114 | VspClosedMsg: cfg.VspClosedMsg, |
101 | | - AdminPass: cfg.AdminPass, |
| 115 | + AdminAuthSHA: adminAuthSHA, |
102 | 116 | Debug: cfg.WebServerDebug, |
103 | 117 | Designation: cfg.Designation, |
104 | 118 | MaxVoteChangeRecords: maxVoteChangeRecords, |
|
0 commit comments