-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogs.nim
80 lines (54 loc) · 2.32 KB
/
dialogs.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import nigui
import osproc
import strutils
import sequtils
import passutils
import std/random
import system
randomize()
proc showError*(text: string) =
discard execCmd("zenity --error --title='' --text=\'$1\'" % text)
proc showSuccess*(text: string) =
discard execCmd("zenity --info --title='' --text=\'Success! $1\'" % text)
proc show*(name, password: string) =
discard execCmd("zenity --info --title='' --text=\'Name: $1\nPassword: $2\'" % [name, password])
proc initStoragePrompt*(): string =
var cmd = "zenity --entry --hide-text --title='' --text=\'This is the first time you use nimpass. Therefore, storage must be initialized.\n" &
"You have to input new masterkey. It will be used to work with passwords.\nInput masterkey:\'"
var (pass1, es1) = execCmdEx(cmd)
if es1 != 0: return ""
cmd = "zenity --entry --hide-text --title='' --text=\'Please enter the masterkey again:\'"
var (pass2, es2) = execCmdEx(cmd)
if es2 != 0: return ""
pass1 = pass1.strip(chars = {'\n'})
pass2 = pass2.strip(chars = {'\n'})
if pass1 != pass2:
showError("Masterkeys do not match.")
return ""
if pass1.len == 0:
showError("Masterkey can not be empty.")
return ""
return pass1
proc masterkeyPrompt*(): string =
var cmd = "zenity --entry --hide-text --title='' --text=\'Please input masterkey to continue:\'"
var (pass, es) = execCmdEx(cmd)
if es != 0: return ""
pass = pass.strip(chars = {'\n'})
return pass
const randomPasswordLen = 32
let alphabet* = toSeq("1234567890qwertyuiopasdfghjklzxcvbnm!@#$^*+_=-QWERTYUIOPASDFGHJKLZXCVBNM".items)
proc passwordPrompt*(): string =
var cmd = "zenity --question --title='' --text=\"Do you want to use a randomly generated password? " &
"Press Yes if yes, and No if you want to input the password yourself.\"; echo $?"
var (opt, es) = execCmdEx(cmd)
if es != 0: return ""
opt = opt.strip(chars = {'\n'})
var password: string = ""
if opt == "0":
for i in 0..<randomPasswordLen:
password.add(sample(alphabet))
return password
(password, es) = execCmdEx("zenity --entry --hide-text --title='' --text=\"Enter the password:\"")
if es != 0: return ""
password = password.strip(chars = {'\n'})
return password