Skip to content

Commit

Permalink
Issue #4 - Validate existing logins when adding/importing new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
swicherwich committed Sep 26, 2023
1 parent 26317ed commit e4847b1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/app/command/save/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit e4847b1

Please sign in to comment.