-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplePass.py
executable file
·85 lines (70 loc) · 2.49 KB
/
simplePass.py
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
81
82
83
84
#!/usr/bin/env python
import argparse
import hashlib
import pyperclip
import utils.add
import utils.retrieve
import utils.generate
from utils.dbconfig import dbconfig
from random import choice
from getpass import getpass
from rich import print as printc
def parseArgs():
parser = argparse.ArgumentParser(description="Description")
parser.add_argument(
"option",
choices=["a", "add", "e", "extract", "g", "generate"],
help="(a)dd / (e)xtract / (g)enerate",
)
parser.add_argument("-s", "--name", help="Site Name")
parser.add_argument("-u", "--url", help="Site URL")
parser.add_argument("-e", "--email", help="Email")
parser.add_argument("-l", "--login", help="Username")
parser.add_argument("--length", type=int, help="Length of the password to generate")
parser.add_argument(
"-c", "--copy", action="store_true", help="Copy password to clipboard"
)
return parser.parse_args()
def chkMP():
mp = getpass("MASTER PASSWORD: ")
mpHash = hashlib.sha256(mp.encode()).hexdigest()
with dbconfig() as db:
cursor = db.cursor()
cursor.execute("SELECT * FROM sp.secrets")
res = cursor.fetchone()
if mpHash != res[0]:
printc("[red][!] WRONG! [/red]")
return None
return mp, res[1]
def main():
args = parseArgs()
if args.option in ["add", "a"]:
missing = [arg for arg in ["name", "url", "login"] if not getattr(args, arg)]
if missing:
for arg in missing:
printc(f"[red][!][/red] {arg.capitalize()} (-{arg[0]}) required")
return
args.email = args.email or ""
res = chkMP()
if res:
utils.add.addEntry(*res, args.name, args.url, args.email, args.login)
elif args.option in ["extract", "e"]:
res = chkMP()
if res:
search = {
k: v
for k, v in vars(args).items()
if k in ["name", "url", "email", "login"] and v
}
utils.retrieve.retrieveEntries(*res, search, decryptPassword=args.copy)
elif args.option in ["generate", "g"]:
if args.length is None:
printc(
"[red][+][/red] Specify length of the password to generate (--length)"
)
return
password = utils.generate.generatePassword(args.length)
pyperclip.copy(password)
printc("[green][+][/green] Password generated and copied to clipboard")
if __name__ == "__main__":
main()