don't log full password string

This commit is contained in:
2021-08-08 16:56:45 -04:00
parent a0b2bffcb3
commit 2803ce919a
2 changed files with 22 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"log"
"os"
"runtime/debug"
"strings"
"sync"
"git.yetaga.in/alazyreader/library/book"
@@ -47,6 +48,13 @@ func (s *State) Set(key string, value interface{}) {
s.stateMap[key] = value
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
// UI states
const (
IN_MENU = iota
@@ -66,6 +74,9 @@ func main() {
// set up DB connection
if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" {
if c.DBPass != "" { // obscure password
c.DBPass = c.DBPass[0:max(3, len(c.DBPass))] + strings.Repeat("*", max(0, len(c.DBPass)-3))
}
log.Fatalf("vars: %+v", c)
}
lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName)