44from libwardenpy .colors import colored_string , print_colored
55from libwardenpy .db import get_connection
66from libwardenpy .funtionality import (
7+ AuthenticatedData ,
8+ Entry ,
9+ UnAuthData ,
710 add_password ,
811 authenticate_user ,
912 delete_passwod ,
1619
1720authenticated = False
1821
22+ data : UnAuthData = UnAuthData ("" , "" )
23+ auth_data : AuthenticatedData = AuthenticatedData ("" , b"" )
24+
1925
2026def init_store (args ) -> None :
27+ global data
2128 migrate_DB ()
2229 USER_NAME_EXIST = False
2330 with get_connection () as conn :
2431 cursor = conn .execute ("SELECT username FROM users;" )
25- username = args .username
26- if (username ,) in cursor .fetchall ():
32+ data . username = args .username
33+ if (data . username ,) in cursor .fetchall ():
2734 USER_NAME_EXIST = True
2835 if not USER_NAME_EXIST :
2936 tips_text1 = (
3037 "create a strong and memorable password\n "
3138 "guide: https://anonymousplanet.org/guide.html#appendix-a2-guidelines-for-passwords-and-passphrases\n "
3239 )
3340 print_colored (tips_text1 , "red" )
34- password = input ("Create Strong and Memorable Master Password: " )
35- register_user (username , password )
41+ data . master_password = input ("Create Strong and Memorable Master Password: " )
42+ register_user (get_connection (), data )
3643 else :
3744 print ("Username exit" )
3845 exit ()
3946
4047
4148def main () -> None :
42- global authenticated
49+ global authenticated , auth_data , data , pool
4350 args = parse_arguments ()
51+ data .username = args .username
52+ data .master_password = args .password
4453 if args .password is not None and args .username is not None :
45- password = args .password
46- if authenticate_user (args .username , password ) is not None :
54+ key = authenticate_user (get_connection (), data )
55+ if key is not None :
56+ auth_data .key = key
4757 authenticated = True
4858 elif args .username is not None and args .password is None :
49- password = input ("Enter Master Password: " )
50- args . password = password
51- if authenticate_user ( args . username , password ) is not None :
59+ data . master_password = input ("Enter Master Password: " )
60+ key = authenticate_user ( get_connection (), data )
61+ if key is not None :
5262 authenticated = True
63+ auth_data .key = key
5364
65+ auth_data .username = data .username
5466 if authenticated :
5567 banner = r"""
5668__ __ _ ______ __
@@ -65,14 +77,15 @@ def main() -> None:
6577 1.) Add a Entry [A]
6678 2.) Search Entry [S]
6779 3.) List Entries [L]
68- 4.) Delete Entry [D]
6980 4.) Delete Entry [D]
7081 """
7182 print (banner )
72- main_logic (args )
83+ main_logic ()
7384
7485
75- def main_logic (args ):
86+ def main_logic ():
87+ global auth_data
88+ print (auth_data .key )
7689 while True :
7790 user_input = input ("> " )
7891 if user_input .upper () == ".CLEAR" :
@@ -93,32 +106,41 @@ def main_logic(args):
93106 site_pass = input (".add password (leave this blank for random password) > " )
94107 if not site_pass :
95108 site_pass = generate_password ()
96- add_password (args .username , args .password , site , site_pass )
109+ entry : Entry = Entry (site , site_pass )
110+ add_password (get_connection (), auth_data , entry )
97111 if (
98112 user_input == "2"
99113 or user_input .upper () == "S"
100114 or user_input .upper () == ".SEARCH"
101115 ):
102116 site = input (".search > " )
103- get_password (args .username , args .password , site )
117+ a = get_password (get_connection (), auth_data , site )
118+ print (a )
104119
105120 if (
106121 user_input == "3"
107122 or user_input .upper () == "L"
108123 or user_input .upper () == ".LIST"
109124 ):
110- list_passwords (args .username , args .password )
125+ passwords = list_passwords (get_connection (), auth_data )
126+ if passwords is None :
127+ print (f"No passwords for user { auth_data .username } " )
128+ print (passwords )
111129 if user_input .upper () == "D" or user_input .upper () == ".DEL" :
112130 while True :
113131 site = input (".search entry > " ).strip ()
114132 if not site :
115133 print (colored_string ("You Must Add a Website .^." , "RED" ))
116134 else :
117135 break
118- get_password (args .username , args .password , site , 1 )
119- id = input ("Give the id of the entry you want to delete > " )
120- id = str (id ).strip ()
121- delete_passwod (args .username , args .password , id )
136+ list_of_entries = get_password (get_connection (), auth_data , site )
137+ if list_of_entries is None :
138+ print (f"no entries have { site } " )
139+ if list_of_entries is not None :
140+ print (list_of_entries )
141+ id = input ("Give the id of the entry you want to delete > " )
142+ id = str (id ).strip ()
143+ delete_passwod (get_connection (), auth_data , id )
122144 if user_input .upper () == "X" or user_input .upper () == ".EXIT" :
123145 break
124146
0 commit comments