bot: add override password for staging/testing modes

This commit is contained in:
Chris Sexton 2022-07-17 13:46:44 -04:00
parent 96229c9e11
commit 55ba4996eb
1 changed files with 5 additions and 1 deletions

View File

@ -318,6 +318,9 @@ func (b *bot) Register(p Plugin, kind Kind, cb Callback) {
// GetPassword returns a random password generated for the bot // GetPassword returns a random password generated for the bot
// Passwords expire in 24h and are used for the web interface // Passwords expire in 24h and are used for the web interface
func (b *bot) GetPassword() string { func (b *bot) GetPassword() string {
if override := b.config.Get("bot.password", ""); override != "" {
return override
}
if b.passwordCreated.Before(time.Now().Add(-24 * time.Hour)) { if b.passwordCreated.Before(time.Now().Add(-24 * time.Hour)) {
adjs := b.config.GetArray("bot.passwordAdjectives", []string{"very"}) adjs := b.config.GetArray("bot.passwordAdjectives", []string{"very"})
nouns := b.config.GetArray("bot.passwordNouns", []string{"noun"}) nouns := b.config.GetArray("bot.passwordNouns", []string{"noun"})
@ -404,10 +407,11 @@ func PluginName(p Plugin) string {
} }
func (b *bot) CheckPassword(secret, password string) bool { func (b *bot) CheckPassword(secret, password string) bool {
log.Debug().Msgf("CheckPassword(%s, %s) => b.password=%s, b.GetPassword()=%s", secret, password, b.password, b.GetPassword())
if password == "" { if password == "" {
return false return false
} }
if b.password == password { if b.GetPassword() == password {
return true return true
} }
parts := strings.SplitN(password, ":", 2) parts := strings.SplitN(password, ":", 2)