Browse Source

Adds environment variable to set the initial admin password

This change adds a `GOPHISH_INITIAL_ADMIN_PASSWORD` environment variable so that system administrators can set the initial admin password rather than having it randomly generated. This is especially useful in automated deployment scenarios, or scenarios using Docker (ref #1876, #1874)
pull/1883/head
Jordan Wright 1 year ago
parent
commit
bf76f86ea4
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      models/models.go

+ 14
- 3
models/models.go View File

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"time"
"bitbucket.org/liamstask/goose/lib/goose"
@ -28,6 +29,11 @@ const MaxDatabaseConnectionAttempts int = 10
// DefaultAdminUsername is the default username for the administrative user
const DefaultAdminUsername = "admin"
// InitialAdminPassword is the environment variable that specifies which
// password to use for the initial root login instead of generating one
// randomly
const InitialAdminPassword = "GOPHISH_INITIAL_ADMIN_PASSWORD"
const (
CampaignInProgress string = "In progress"
CampaignQueued string = "Queued"
@ -88,9 +94,14 @@ func chooseDBDriver(name, openStr string) goose.DBDriver {
}
func createTemporaryPassword(u *User) error {
// This will result in a 16 character password which could be viewed as an
// inconvenience, but it should be ok for now.
temporaryPassword := auth.GenerateSecureKey(auth.MinPasswordLength)
var temporaryPassword string
if envPassword := os.Getenv(InitialAdminPassword); envPassword != "" {
temporaryPassword = envPassword
} else {
// This will result in a 16 character password which could be viewed as an
// inconvenience, but it should be ok for now.
temporaryPassword = auth.GenerateSecureKey(auth.MinPasswordLength)
}
hash, err := auth.GeneratePasswordHash(temporaryPassword)
if err != nil {
return err

Loading…
Cancel
Save