From 96772b575428c61eb3e0d86a6e7184a80cf0e716 Mon Sep 17 00:00:00 2001 From: Anand Date: Fri, 3 Dec 2021 19:19:21 +0530 Subject: [PATCH 1/4] ref issue #8 - option to generate password -g --- main.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index fdd24c3..927f8ff 100644 --- a/main.go +++ b/main.go @@ -4,13 +4,14 @@ package main import ( "fmt" + "strconv" getopt "github.com/pborman/getopt/v2" "os" ) const VERSION = 0.2 const APP = "varuh" -const AUTHOR_EMAIL = "Anand B Pillai " +const AUTHOR_EMAIL = "Anand B Pillai " type actionFunc func(string) error type actionFunc2 func(string) (error, string) @@ -32,6 +33,30 @@ func printVersionInfo() error { return nil } +// Command-line wrapper to generateRandomPassword +func generatePassword(length string) (error, string) { + var iLength int + var err error + var passwd string + + iLength, _ = strconv.Atoi(length) + err, passwd = generateRandomPassword(iLength) + + if err != nil { + fmt.Printf("Error generating password - \"%s\"\n", err.Error()) + return err, "" + } + + fmt.Println(passwd) + + if settingsRider.CopyPassword { + copyPasswordToClipboard(passwd) + fmt.Println("Password copied to clipboard") + } + + return nil, passwd +} + // Perform an action by using the command line options map func performAction(optMap map[string]interface{}, optionMap map[string]interface{}) { @@ -59,6 +84,7 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface stringActions2Map := map[string]actionFunc2{ "decrypt": decryptDatabase, + "genpass": generatePassword, } flagsActionsMap := map[string]voidFunc{ @@ -70,7 +96,6 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface for key, mappedFunc := range flagsActionsMap { if *optMap[key].(*bool) { mappedFunc() - break } } From 3597fb6ca2ad42c96475a6479cec6b0f401ef69b Mon Sep 17 00:00:00 2001 From: Anand Date: Fri, 3 Dec 2021 19:19:45 +0530 Subject: [PATCH 2/4] ref issue #8 - option to generate password -g --- options.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index cc9d7b8..c27a9a9 100644 --- a/options.go +++ b/options.go @@ -31,6 +31,10 @@ OPTIONS FIND/LIST ACTIONS: +%s + + MISC ACTIONS: + %s HELP ACTIONS: @@ -53,6 +57,7 @@ func usageString(optMap map[string]interface{}) { var findActions []string var helpActions []string var flagActions []string + var miscActions []string var maxLen1 int var maxLen2 int @@ -95,12 +100,18 @@ func usageString(optMap map[string]interface{}) { helpActions = append(helpActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help)) case 3: flagActions = append(flagActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help)) + case 4: + miscActions = append(miscActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help)) } } - fmt.Println(fmt.Sprintf(HELP_STRING, APP, strings.Join(editActions, "\n"), - strings.Join(findActions, "\n"), strings.Join(helpActions, "\n"), - strings.Join(flagActions, "\n"), AUTHOR_EMAIL)) + fmt.Println(fmt.Sprintf(HELP_STRING, APP, + strings.Join(editActions, "\n"), + strings.Join(findActions, "\n"), + strings.Join(miscActions, "\n"), + strings.Join(helpActions, "\n"), + strings.Join(flagActions, "\n"), + AUTHOR_EMAIL)) } @@ -122,6 +133,7 @@ func initializeCommandLine() (map[string]interface{}, map[string]interface{}) { {'E', "edit", "", "Edit entry by id", 0}, {'l', "list-entry", "", "List entry by id", 1}, {'x', "export", "", "Export all entries to ", 1}, + {'g', "genpass", "", "Generate password of given length", 4}, } for _, opt := range stringOptions { From 441f361e01443b9e746ef65a64ee1df1f1a864dc Mon Sep 17 00:00:00 2001 From: Anand Date: Fri, 3 Dec 2021 19:20:12 +0530 Subject: [PATCH 3/4] ref issue #8 - updated source for generateRandomPassword --- crypto.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto.go b/crypto.go index af595e6..924031f 100644 --- a/crypto.go +++ b/crypto.go @@ -438,7 +438,7 @@ func decryptFileXChachaPoly(encDbPath string, password string) error { func generateRandomPassword(length int) (error, string) { var data []byte - const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#!+$@~" + const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?)(/%#!?)=" data = make([]byte, length) From 08323c26380081af4248fa1102a44828d01c70ac Mon Sep 17 00:00:00 2001 From: Anand Date: Tue, 7 Dec 2021 00:17:23 +0530 Subject: [PATCH 4/4] Updated README for issue #8 --- README.md | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c25898b..b81d83a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Table of Contents * [Encryption and Security](#encryption-and-security) * [Databases](#databases) * [Listing and Searching](#listing-and-searching) +* [Misc](#misc) * [Export](#export) * [Configuration](#configuration) * [License](#license) @@ -67,6 +68,7 @@ Usage $ varuh -h + SYNOPSIS varuh [options] [flags] @@ -75,22 +77,26 @@ Usage EDIT/CREATE ACTIONS: - -C --clone Clone an entry - -U --use-db Set as active database - -E --edit Edit entry by id -A --add Add a new entry -I --init Initialize a new database - -d --decrypt Decrypt password database - -e --encrypt Encrypt the current database -R --remove Remove an entry + -e --encrypt Encrypt the current database + -d --decrypt Decrypt password database + -C --clone Clone an entry + -U --use-db Set as active database + -E --edit Edit entry by id FIND/LIST ACTIONS: - -x --export Export all entries to - -a --list-all List all entries in current database - -p --path Show current database path -f --find Search entries -l --list-entry List entry by id + -x --export Export all entries to + -p --path Show current database path + -a --list-all List all entries in current database + + MISC ACTIONS: + + -g --genpass Generate password of given length HELP ACTIONS: @@ -104,10 +110,10 @@ Usage AUTHORS - Copyright (C) 2021 Anand B Pillai + Copyright (C) 2021 Anand B Pillai -The command line flags are grouped into `Edit/Create`, `Find/List` and `Help` actions. The first group of actions allows you to work with password databases and perform create/edit as well as encrypt/decrypt actions. The second set of actions allows you to work with an active decrypted database and view/search/list entries. +The command line flags are grouped into `Edit/Create`, `Find/List`, `Misc` and `Help` actions. The first group of actions allows you to work with password databases and perform create/edit as well as encrypt/decrypt actions. The second set of actions allows you to work with an active decrypted database and view/search/list entries. Encryption and Security ======================= @@ -439,6 +445,22 @@ If `pdftk` is installed, the PDF files will be encrypted with an (optional) pass Added password to passwds.pdf. Exported to passwds.pdf. +Misc +==== + +The following miscellaneous actions are supported. + +Generate a secure password of given length. + + $ varuh -g + 7nhga7tkk9LNafz + + By passing the `-c` option, the password is also copied to the clipboard. + + $ varuh -g 15 -c + yeXlLlk??IOsvL6 + Password copied to clipboard + Configuration =============