Skip to content

Commit

Permalink
Add: edit command & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinjamul committed Mar 11, 2021
1 parent e8453f6 commit 346b143
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 94 deletions.
72 changes: 72 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
v1.1.0
Changelog:
new command edit
Improve codebase

v1.0.2
Changelog:
Improve search cmd

v1.0.1
Changelog:
minor changes

v1.0.0
Changelog:
#10 use pager for viewing password
minor changes


v0.7.1
Changelog:
small changes


v0.7.0
Changelog:
reset & restore (redesigned)


v0.6.0
Changelog:
search command added
bug fixes and improved

v0.5.0
Changelog:
added a new feature (import CSV files) import -c
fixes
Now, you can import google-chrome passwords into gpassmanager using CSV file.


v0.4.1
Changelog:
new feature (batch deletion)
bug fixes

v0.4.0
Changelog:
New features (password generator)

v0.3.1
Changelog:
bug fixes

v0.3.0
Changelog:
new features added
fix errors

v0.2.0
Changelog:
new features added
fix typo and errors

v0.1.0
Changelog:
add export & import features
fix errors

v0.0.1-beta
Changelog:
gpassmanager version 0.0.1-beta
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2020-2021 Injamul Mohammad Mollah <mrinjamul@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Using Go Password Manager is easy. First, use `go get` to install the latest ver
For Linux,

```sh
wget https://github.com/mrinjamul/gpassmanager/releases/download/v1.0.2/gpassmanager-linux-amd64-v1.0.2.tar.gz
tar xvf gpassmanager-linux-amd64-v1.0.2.tar.gz
wget https://github.com/mrinjamul/gpassmanager/releases/download/v1.1.0/gpassmanager-linux-amd64-v1.1.0.tar.gz
tar xvf gpassmanager-linux-amd64-v1.1.0.tar.gz
chmod +x gpassmanager
sudo mv gpassmanager /usr/bin
```
Expand All @@ -55,13 +55,13 @@ You need to have `tar wget`. To install simply type `pkg install tar wget`

```sh
cd ~
wget https://github.com/mrinjamul/gpassmanager/releases/download/v1.0.2/gpassmanager-linux-arm-v1.0.2.tar.gz
tar xvf gpassmanager-linux-arm-v1.0.2.tar.gz
wget https://github.com/mrinjamul/gpassmanager/releases/download/v1.1.0/gpassmanager-linux-arm-v1.1.0.tar.gz
tar xvf gpassmanager-linux-arm-v1.1.0.tar.gz
chmod +x gpassmanager
mv gpassmanager ../usr/bin
```

[Note: if new version available you need to download and install by the same process. The above instructions will install v1.0.2 .]
[Note: if new version available you need to download and install by the same process. The above instructions will install v1.1.0 .]

## Usage

Expand All @@ -74,6 +74,7 @@ mv gpassmanager ../usr/bin
Available Commands:
add Add new password
change Change Master Password
edit Edit a account details
export export your data to a file (master key will be also exported)
generate Generate secure password
help Help about any command
Expand All @@ -86,7 +87,6 @@ mv gpassmanager ../usr/bin
view view all passwords

Flags:
--config string config file (default is $HOME/.gpassmanager.yaml)
-h, --help help for gpassmanager

Use "gpassmanager [command] --help" for more information about a command.
Expand Down
2 changes: 1 addition & 1 deletion cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/change.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
184 changes: 184 additions & 0 deletions cmd/edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"syscall"

"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/mrinjamul/gpassmanager/gpm"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

// editCmd represents the edit command
var editCmd = &cobra.Command{
Use: "edit",
Aliases: []string{"ed", "modify"},
Short: "Edit a account details",
Long: `Edit a account details`,
Run: editRun,
}

func editRun(cmd *cobra.Command, args []string) {
// Check if database exists
_, err := os.Stat(gpm.DatabaseFile)
if os.IsNotExist(err) {
color.Red("Error: No account exists")
os.Exit(1)
}
// Get raw data for checking
data, err := ioutil.ReadFile(gpm.DatabaseFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(data) == 0 {
fmt.Println("No passwords found !")
os.Exit(0)
}
// only take arg as integer
id, err := strconv.Atoi(args[0])
if err != nil || id == 0 {
color.Red(args[id] + " is not a valid id\ninvalid syntax")
os.Exit(0)
}
if id < 0 {
color.Red(args[id] + " is not a valid id\ninvalid syntax")
os.Exit(0)
}

// as array index
id = id - 1

// secure user input
fmt.Print("password: ")
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
fmt.Println()
// password verifications
if len(data) != 0 && gpm.VerifyKey(bytePassword, data) == false {
color.Red("Error: Wrong password !")
os.Exit(1)
}
// decrypt and get All accounts
accounts, err := gpm.ReadPasswords(bytePassword)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
if len(accounts) == 0 {
fmt.Println("No passwords found !")
os.Exit(0)
}
// View section
printableData := "\n"
printableData += gpm.LineBreak()
printableData += "[" + strconv.Itoa(id+1) + "]" + "\t" + "Account: " + accounts[id].AccountName + "\n"
printableData += "Username: " + accounts[id].UserName + "\n"
printableData += "Password: " + accounts[id].Password + "\n"
if accounts[id].Email != "" {
printableData += "Email: " + accounts[id].Email + "\n"
}
if accounts[id].Phone != "" {
printableData += "Mobile no: " + accounts[id].Phone + "\n"
}
if accounts[id].Notes != "" {
printableData += "Notes: " + accounts[id].Notes + "\n"
}
printableData += gpm.LineBreak()
printableData += "\n"
fmt.Print(printableData)

// Edit section
// scanner for taking user input as line
scanner := bufio.NewScanner(os.Stdin)

fmt.Print("Enter Account Name: ")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].AccountName = scanner.Text()
}
}
fmt.Print("Enter username: ")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].UserName = scanner.Text()
}
}
fmt.Print("Enter password: ")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].Password = scanner.Text()
}
}

fmt.Print("Enter email: ")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].Email = scanner.Text()
}
}
fmt.Print("Enter mobile no: ")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].Phone = scanner.Text()
}
}
fmt.Print("Notes :")
if scanner.Scan() {
if scanner.Text() != "" {
accounts[id].Notes = scanner.Text()
}
}
fmt.Println()
fmt.Println(gpm.LineBreak())
// prompt for confirmations
prompt := promptui.Select{
Label: "Do you want to save (Yes/No)",
Items: []string{"Yes", "No"},
}
_, result, err := prompt.Run()
if err != nil {
log.Fatalf("Prompt failed %v\n", err)
}
if result == "Yes" {
gpm.SavePasswords(bytePassword, accounts)
color.Green("Password Saved!")
} else {
fmt.Println("Password Not Saved!")
}
}

func init() {
rootCmd.AddCommand(editCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// editCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// editCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
2 changes: 1 addition & 1 deletion cmd/export.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/license.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 4 additions & 2 deletions cmd/remove.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,9 @@ func removeRun(cmd *cobra.Command, args []string) {
color.Red(args[arg] + " is not a valid id\ninvalid syntax")
os.Exit(0)
}
rmList = append(rmList, i)
if i > 0 {
rmList = append(rmList, i)
}
}
// sort and remove duplicate
rmList = gpm.SortSlice(rmList)
Expand Down
2 changes: 1 addition & 1 deletion cmd/reset.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package cmd ...
/*
Copyright © 2020 Injamul Mohammad Mollah
Copyright © 2020-2021 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,8 +59,9 @@ func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gpassmanager.yaml)")
//
// Uncomment below line to enable configurable app
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gpassmanager.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
Expand Down
Loading

0 comments on commit 346b143

Please sign in to comment.