Skip to content

Commit dff7829

Browse files
authored
Merge pull request #11 from pythonhacker/development
Development
2 parents 35cc37c + 08323c2 commit dff7829

File tree

4 files changed

+75
-16
lines changed

4 files changed

+75
-16
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Table of Contents
1111
* [Encryption and Security](#encryption-and-security)
1212
* [Databases](#databases)
1313
* [Listing and Searching](#listing-and-searching)
14+
* [Misc](#misc)
1415
* [Export](#export)
1516
* [Configuration](#configuration)
1617
* [License](#license)
@@ -67,6 +68,7 @@ Usage
6768

6869
$ varuh -h
6970

71+
7072
SYNOPSIS
7173

7274
varuh [options] [flags]
@@ -75,22 +77,26 @@ Usage
7577

7678
EDIT/CREATE ACTIONS:
7779

78-
-C --clone <id> Clone an entry
79-
-U --use-db <path> Set as active database
80-
-E --edit <id> Edit entry by id
8180
-A --add Add a new entry
8281
-I --init <path> Initialize a new database
83-
-d --decrypt <path> Decrypt password database
84-
-e --encrypt Encrypt the current database
8582
-R --remove <id> Remove an entry
83+
-e --encrypt Encrypt the current database
84+
-d --decrypt <path> Decrypt password database
85+
-C --clone <id> Clone an entry
86+
-U --use-db <path> Set as active database
87+
-E --edit <id> Edit entry by id
8688

8789
FIND/LIST ACTIONS:
8890

89-
-x --export <filename> Export all entries to <filename>
90-
-a --list-all List all entries in current database
91-
-p --path Show current database path
9291
-f --find <term> Search entries
9392
-l --list-entry <id> List entry by id
93+
-x --export <filename> Export all entries to <filename>
94+
-p --path Show current database path
95+
-a --list-all List all entries in current database
96+
97+
MISC ACTIONS:
98+
99+
-g --genpass <length> Generate password of given length
94100

95101
HELP ACTIONS:
96102

@@ -104,10 +110,10 @@ Usage
104110

105111

106112
AUTHORS
107-
Copyright (C) 2021 Anand B Pillai <anandpillai@alumni.iitm.ac.in>
113+
Copyright (C) 2021 Anand B Pillai <abpillai@gmail.com>
108114

109115

110-
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.
116+
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.
111117

112118
Encryption and Security
113119
=======================
@@ -439,6 +445,22 @@ If `pdftk` is installed, the PDF files will be encrypted with an (optional) pass
439445
Added password to passwds.pdf.
440446
Exported to passwds.pdf.
441447

448+
Misc
449+
====
450+
451+
The following miscellaneous actions are supported.
452+
453+
Generate a secure password of given length.
454+
455+
$ varuh -g
456+
7nhga7tkk9LNafz
457+
458+
By passing the `-c` option, the password is also copied to the clipboard.
459+
460+
$ varuh -g 15 -c
461+
yeXlLlk??IOsvL6
462+
Password copied to clipboard
463+
442464

443465
Configuration
444466
=============

crypto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func decryptFileXChachaPoly(encDbPath string, password string) error {
438438
func generateRandomPassword(length int) (error, string) {
439439

440440
var data []byte
441-
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#!+$@~"
441+
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?)(/%#!?)="
442442

443443
data = make([]byte, length)
444444

main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ package main
44

55
import (
66
"fmt"
7+
"strconv"
78
getopt "github.com/pborman/getopt/v2"
89
"os"
910
)
1011

1112
const VERSION = 0.2
1213
const APP = "varuh"
13-
const AUTHOR_EMAIL = "Anand B Pillai <anandpillai@alumni.iitm.ac.in>"
14+
const AUTHOR_EMAIL = "Anand B Pillai <abpillai@gmail.com>"
1415

1516
type actionFunc func(string) error
1617
type actionFunc2 func(string) (error, string)
@@ -32,6 +33,30 @@ func printVersionInfo() error {
3233
return nil
3334
}
3435

36+
// Command-line wrapper to generateRandomPassword
37+
func generatePassword(length string) (error, string) {
38+
var iLength int
39+
var err error
40+
var passwd string
41+
42+
iLength, _ = strconv.Atoi(length)
43+
err, passwd = generateRandomPassword(iLength)
44+
45+
if err != nil {
46+
fmt.Printf("Error generating password - \"%s\"\n", err.Error())
47+
return err, ""
48+
}
49+
50+
fmt.Println(passwd)
51+
52+
if settingsRider.CopyPassword {
53+
copyPasswordToClipboard(passwd)
54+
fmt.Println("Password copied to clipboard")
55+
}
56+
57+
return nil, passwd
58+
}
59+
3560
// Perform an action by using the command line options map
3661
func performAction(optMap map[string]interface{}, optionMap map[string]interface{}) {
3762

@@ -59,6 +84,7 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
5984

6085
stringActions2Map := map[string]actionFunc2{
6186
"decrypt": decryptDatabase,
87+
"genpass": generatePassword,
6288
}
6389

6490
flagsActionsMap := map[string]voidFunc{
@@ -70,7 +96,6 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
7096
for key, mappedFunc := range flagsActionsMap {
7197
if *optMap[key].(*bool) {
7298
mappedFunc()
73-
break
7499
}
75100
}
76101

options.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ OPTIONS
3131
3232
FIND/LIST ACTIONS:
3333
34+
%s
35+
36+
MISC ACTIONS:
37+
3438
%s
3539
3640
HELP ACTIONS:
@@ -53,6 +57,7 @@ func usageString(optMap map[string]interface{}) {
5357
var findActions []string
5458
var helpActions []string
5559
var flagActions []string
60+
var miscActions []string
5661

5762
var maxLen1 int
5863
var maxLen2 int
@@ -95,12 +100,18 @@ func usageString(optMap map[string]interface{}) {
95100
helpActions = append(helpActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
96101
case 3:
97102
flagActions = append(flagActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
103+
case 4:
104+
miscActions = append(miscActions, fmt.Sprintf(usageTemplate, "-"+string(option.Short), option.Long, option.Path, option.Help))
98105
}
99106
}
100107

101-
fmt.Println(fmt.Sprintf(HELP_STRING, APP, strings.Join(editActions, "\n"),
102-
strings.Join(findActions, "\n"), strings.Join(helpActions, "\n"),
103-
strings.Join(flagActions, "\n"), AUTHOR_EMAIL))
108+
fmt.Println(fmt.Sprintf(HELP_STRING, APP,
109+
strings.Join(editActions, "\n"),
110+
strings.Join(findActions, "\n"),
111+
strings.Join(miscActions, "\n"),
112+
strings.Join(helpActions, "\n"),
113+
strings.Join(flagActions, "\n"),
114+
AUTHOR_EMAIL))
104115

105116
}
106117

@@ -122,6 +133,7 @@ func initializeCommandLine() (map[string]interface{}, map[string]interface{}) {
122133
{'E', "edit", "<id>", "Edit entry by id", 0},
123134
{'l', "list-entry", "<id>", "List entry by id", 1},
124135
{'x', "export", "<filename>", "Export all entries to <filename>", 1},
136+
{'g', "genpass", "<length>", "Generate password of given length", 4},
125137
}
126138

127139
for _, opt := range stringOptions {

0 commit comments

Comments
 (0)