user security best practice of having no default passwords.

This commit is contained in:
Erik Brakkee 2024-07-26 20:57:04 +02:00
parent d02b7eade3
commit 37bef8814c

View File

@ -6,10 +6,12 @@ import (
"converge/pkg/websocketutil" "converge/pkg/websocketutil"
"fmt" "fmt"
"log" "log"
"math/rand"
"net" "net"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"strconv"
"strings" "strings"
) )
@ -71,16 +73,23 @@ func main() {
printHelp("") printHelp("")
} }
userPassword := comms.UserPassword{
Username: strconv.Itoa(rand.Int()),
Password: strconv.Itoa(rand.Int()),
}
username, ok := os.LookupEnv("CONVERGE_USERNAME") username, ok := os.LookupEnv("CONVERGE_USERNAME")
if !ok { if ok {
username = "abc" userPassword.Username = username
} }
password, ok := os.LookupEnv("CONVERGE_PASSWORD") password, ok := os.LookupEnv("CONVERGE_PASSWORD")
if !ok { if ok {
password = "123" userPassword.Password = password
} }
log.Printf("Using username '%s' and password '%s'", userPassword.Username, userPassword.Password)
admin := converge.NewAdmin() admin := converge.NewAdmin()
registrationService := websocketutil.WebSocketService{ registrationService := websocketutil.WebSocketService{
Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) { Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) {
@ -91,7 +100,7 @@ func main() {
} }
log.Printf("Got registration connection: '%s'\n", publicId) log.Printf("Got registration connection: '%s'\n", publicId)
err = admin.Register(publicId, conn, err = admin.Register(publicId, conn,
comms.UserPassword{Username: username, Password: password}) userPassword)
if err != nil { if err != nil {
log.Printf("Error %v\n", err) log.Printf("Error %v\n", err)
} }