Skip to content

Commit

Permalink
fix: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinjamul committed Sep 22, 2020
1 parent 4605e7b commit 6e93f1d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"log"
Expand All @@ -44,7 +45,6 @@ func addRun(cmd *cobra.Command, args []string) {
gpm.CreateDatabase()
}
var account gpm.Account
var password string
var accounts []gpm.Account

data, err := ioutil.ReadFile(gpm.DatabaseFile)
Expand All @@ -54,21 +54,28 @@ func addRun(cmd *cobra.Command, args []string) {
}
if len(data) == 0 {
color.Red("Warning: If you forget your master password your data will be lost !!")
color.Yellow("Master password can contains characters and symbols.")
fmt.Println()
}
fmt.Print("password: ")
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
fmt.Println()

password = string(bytePassword)
if password == "" {
if string(bytePassword) == "" {
color.Red("Error: you haven't entered password")
if len(data) == 0 {
color.Red("Master password can't be empty")
}
os.Exit(0)
}
if len(data) == 0 && len(password) < 6 {

if len(data) == 0 && bytes.ContainsAny(bytePassword, "0123456789") {
color.Red("Error: master key can't have numbers !!")
color.Yellow("Tips: Use passphrases instead")
os.Exit(0)
}

if len(data) == 0 && len(string(bytePassword)) < 6 {
color.Red("Master password must be greater than 5")
os.Exit(0)
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cmd

import (
"bytes"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -69,12 +70,30 @@ func changeRun(cmd *cobra.Command, args []string) {
color.Red("Error: Password already in use !!")
os.Exit(0)
}

if string(byteNewPassword) == "" {
color.Red("Error: you haven't entered password")
os.Exit(0)
}

if bytes.ContainsAny(byteNewPassword, "0123456789") {
color.Red("Error: master key can't have numbers !!")
color.Yellow("Tips: Use passphrases instead")
os.Exit(0)
}

if len(string(byteNewPassword)) < 6 {
color.Red("Master password must be greater than 5")
os.Exit(0)
}

fmt.Print("Verify password: ")
byteVerifyPassword, _ := terminal.ReadPassword(int(syscall.Stdin))
fmt.Println()

if string(byteNewPassword) != string(byteVerifyPassword) {
color.Red("Error: both password is not same!")
os.Exit(0)
}

prompt := promptui.Select{
Expand Down
2 changes: 1 addition & 1 deletion gpm/gpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GetHomeDir() string {

// GetVersion returns version name, and code
func GetVersion() string {
var version = "0.3.0"
var version = "0.3.1"
return version
}

Expand Down

0 comments on commit 6e93f1d

Please sign in to comment.