-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d6d6eb
commit efc84ba
Showing
6 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea | ||
.idea | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package remove | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/swicherwich/pwdmg/internal/app/domain" | ||
"github.com/swicherwich/pwdmg/internal/pkg/fsutil" | ||
"github.com/swicherwich/pwdmg/internal/pkg/secutil" | ||
"time" | ||
) | ||
|
||
func RemoveAccount(d, acc string) error { | ||
pwdmgDir, _ := fsutil.GetPwdmgDir() | ||
|
||
dHash := secutil.HashStr(d) | ||
accHash := secutil.HashStr(acc) | ||
dFile := fmt.Sprintf("%s/%s%s", pwdmgDir, dHash, ".json") | ||
|
||
if fsutil.FileExists(dFile) { | ||
var d domain.Domain | ||
|
||
if err := fsutil.ReadData(dFile, &d); err != nil { | ||
return err | ||
} | ||
|
||
for i := range d.Accounts { | ||
account := &d.Accounts[i] | ||
if account.Login == accHash { | ||
d.Metadata = domain.Metadata{ | ||
Entries: d.Metadata.Entries - 1, | ||
LastModified: time.Now().Format(time.DateTime), | ||
} | ||
|
||
d.Accounts = append(d.Accounts[:i], d.Accounts[i+1:]...) | ||
|
||
if err := fsutil.PersistDataToFile(dFile, d); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
} | ||
|
||
return errors.New("no such login") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package update | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/swicherwich/pwdmg/internal/app/domain" | ||
"github.com/swicherwich/pwdmg/internal/pkg/fsutil" | ||
"github.com/swicherwich/pwdmg/internal/pkg/secutil" | ||
"time" | ||
) | ||
|
||
func UpdatePassword(d, acc, pwd string) error { | ||
pwdmgDir, _ := fsutil.GetPwdmgDir() | ||
|
||
dHash := secutil.HashStr(d) | ||
accHash := secutil.HashStr(acc) | ||
pwd64 := secutil.EncodeBase64(pwd) | ||
dFile := fmt.Sprintf("%s/%s%s", pwdmgDir, dHash, ".json") | ||
|
||
if fsutil.FileExists(dFile) { | ||
var d domain.Domain | ||
|
||
if err := fsutil.ReadData(dFile, &d); err != nil { | ||
return err | ||
} | ||
|
||
for i := range d.Accounts { | ||
account := &d.Accounts[i] | ||
if account.Login == accHash { | ||
d.Metadata = domain.Metadata{ | ||
LastModified: time.Now().Format(time.DateOnly), | ||
} | ||
account.Password = pwd64 | ||
|
||
if err := fsutil.PersistDataToFile(dFile, d); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
} | ||
|
||
return errors.New("no such login") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters