fix: restore default admin password and add reset flag
Restored 'admin123' as the default password in db init and added a -reset-admin flag to main.go.
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"llm-proxy/internal/config"
|
||||
"llm-proxy/internal/db"
|
||||
"llm-proxy/internal/server"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
resetAdmin := flag.Bool("reset-admin", false, "Reset admin password to admin123")
|
||||
flag.Parse()
|
||||
|
||||
// Load environment variables
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("No .env file found")
|
||||
@@ -28,6 +34,16 @@ func main() {
|
||||
log.Fatalf("Failed to initialize database: %v", err)
|
||||
}
|
||||
|
||||
if *resetAdmin {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte("admin123"), 12)
|
||||
_, err = database.Exec("UPDATE users SET password_hash = ?, must_change_password = 1 WHERE username = 'admin'", string(hash))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to reset admin password: %v", err)
|
||||
}
|
||||
log.Println("Admin password has been reset to 'admin123'")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Initialize server
|
||||
s := server.NewServer(cfg, database)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user