From 8f381b28e802f25bd6c5ae56389c91353aa6b658 Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Sun, 6 Aug 2023 12:08:48 -0500 Subject: [PATCH] Add ability to set username --- srepanel/database/passwords.go | 9 +++++++++ srepanel/main.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/srepanel/database/passwords.go b/srepanel/database/passwords.go index e5b24b6..c460018 100644 --- a/srepanel/database/passwords.go +++ b/srepanel/database/passwords.go @@ -66,3 +66,12 @@ func (d *DB) SetPassword(ctx context.Context, id uint64, username, password stri ) return err } + +func (d *DB) SetUsername(ctx context.Context, id uint64, username string) error { + _, err := d.ExecContext( + ctx, + `UPDATE passwords SET username = ? WHERE id = ?`, + username, id, + ) + return err +} diff --git a/srepanel/main.go b/srepanel/main.go index 439ffd4..88edc8b 100644 --- a/srepanel/main.go +++ b/srepanel/main.go @@ -22,6 +22,23 @@ func main() { // cli args if len(os.Args) > 1 { switch os.Args[1] { + case "rename": + os.Args = os.Args[1:] + dbPath := flag.String("db", "ghidra_panel.db", "path to database file") + argUserID := flag.Uint64("user-id", 0, "ID of user to rename") + argUser := flag.String("user", "", "new username") + flag.Parse() + db, err := database.Open(dbPath) + if err != nil { + log.Fatal(err) + } + defer db.Close() + + ctx := context.Background() + if err := db.SetPassword(ctx, userID, user, pass); err != nil { + log.Fatal(err) + } + return case "set-password": os.Args = os.Args[1:] dbPath := flag.String("db", "ghidra_panel.db", "path to database file")