From e4847b1d3def88623b8481eeb86e9b42c06a029d Mon Sep 17 00:00:00 2001 From: Oleh Yashnyi Date: Tue, 26 Sep 2023 23:30:06 +0300 Subject: [PATCH] Issue #4 - Validate existing logins when adding/importing new ones --- internal/app/command/save/save.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/app/command/save/save.go b/internal/app/command/save/save.go index 57b68fe..04d5276 100644 --- a/internal/app/command/save/save.go +++ b/internal/app/command/save/save.go @@ -8,10 +8,10 @@ import ( "time" ) -func PersistAccount(d, acc, pwd string) { +func PersistAccount(dom, acc, pwd string) { pwdmgDir, _ := fsutil.GetPwdmgDir() - dHash := secutil.HashStr(d) + dHash := secutil.HashStr(dom) accHash := secutil.HashStr(acc) pwd64 := secutil.EncodeBase64(pwd) dFile := fmt.Sprintf("%s/%s%s", pwdmgDir, dHash, ".json") @@ -29,6 +29,17 @@ func PersistAccount(d, acc, pwd string) { Entries: d.Metadata.Entries + 1, LastModified: time.Now().Format(time.DateOnly), } + + if len(d.Accounts) > 0 { + for i := range d.Accounts { + account := &d.Accounts[i] + if account.Login == accHash { + fmt.Printf("Login %s is existing for domain %s\n", acc, dom) + return + } + } + } + d.Accounts = append(d.Accounts, domain.Account{Login: accHash, Password: pwd64}) err = fsutil.PersistDataToFile(dFile, d)