mirror of
https://github.com/syntrex-lab/gomcp.git
synced 2026-04-25 04:16:22 +02:00
fix(auth): remove hardcoded admin password and use env var / random generation fallback
This commit is contained in:
parent
05ee9859bf
commit
f833602145
1 changed files with 9 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -65,7 +66,14 @@ func NewUserStore(db ...*sql.DB) *UserStore {
|
|||
|
||||
// Ensure default admin exists
|
||||
if _, err := s.GetByEmail("admin@syntrex.pro"); err != nil {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte("syntrex-admin-2026"), bcrypt.DefaultCost)
|
||||
adminPass := os.Getenv("SYNTREX_ADMIN_PASSWORD")
|
||||
if adminPass == "" {
|
||||
b := make([]byte, 16)
|
||||
rand.Read(b)
|
||||
adminPass = hex.EncodeToString(b)
|
||||
slog.Warn("SYNTREX_ADMIN_PASSWORD not set. Generated random admin password", "password", adminPass)
|
||||
}
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte(adminPass), bcrypt.DefaultCost)
|
||||
admin := &User{
|
||||
ID: generateID("usr"),
|
||||
Email: "admin@syntrex.pro",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue