Skip to content

Commit 4a856e7

Browse files
author
Anand
committed
ref issue #13 - generate strong passwords
1 parent 023045b commit 4a856e7

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"github.com/pythonhacker/argparse"
88
"os"
9-
"strconv"
109
)
1110

1211
const VERSION = 0.3
@@ -20,6 +19,7 @@ AUTHORS
2019
type actionFunc func(string) error
2120
type actionFunc2 func(string) (error, string)
2221
type voidFunc func() error
22+
type voidFunc2 func() (error, string)
2323

2424
// Structure to keep the options data
2525
type CmdOption struct {
@@ -47,13 +47,11 @@ func printVersionInfo() error {
4747
}
4848

4949
// Command-line wrapper to generateRandomPassword
50-
func genPass(length string) (error, string) {
51-
var iLength int
50+
func genPass() (error, string) {
5251
var err error
5352
var passwd string
5453

55-
iLength, _ = strconv.Atoi(length)
56-
err, passwd = generatePassword(iLength)
54+
err, passwd = generateStrongPassword()
5755

5856
if err != nil {
5957
fmt.Printf("Error generating password - \"%s\"\n", err.Error())
@@ -97,6 +95,9 @@ func performAction(optMap map[string]interface{}) {
9795

9896
stringActions2Map := map[string]actionFunc2{
9997
"decrypt": decryptDatabase,
98+
}
99+
100+
flagsActions2Map := map[string]voidFunc2{
100101
"genpass": genPass,
101102
}
102103

@@ -112,6 +113,15 @@ func performAction(optMap map[string]interface{}) {
112113
}
113114
}
114115

116+
// Flag 2 actions
117+
for key, mappedFunc := range flagsActions2Map {
118+
if *optMap[key].(*bool) {
119+
mappedFunc()
120+
flag = true
121+
break
122+
}
123+
}
124+
115125
// One of bool or string actions
116126
for key, mappedFunc := range boolActionsMap {
117127
if *optMap[key].(*bool) {
@@ -164,7 +174,6 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
164174
{"E", "edit", "Edit entry by <id>", "<id>", ""},
165175
{"l", "list-entry", "List entry by <id>", "<id>", ""},
166176
{"x", "export", "Export all entries to <filename>", "<filename>", ""},
167-
{"g", "genpass", "Generate password of given <length>", "<length>", ""},
168177
}
169178

170179
for _, opt := range stringOptions {
@@ -176,6 +185,7 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
176185
{"A", "add", "Add a new entry", "", ""},
177186
{"p", "path", "Show current database path", "", ""},
178187
{"a", "list-all", "List all entries in current database", "", ""},
188+
{"g", "genpass", "Generate a strong password of length from 8 - 12", "", ""},
179189
{"s", "show", "Show passwords when listing entries", "", ""},
180190
{"c", "copy", "Copy password to clipboard", "", ""},
181191
{"v", "version", "Show version information and exit", "", ""},

0 commit comments

Comments
 (0)