10
10
from cryptography .hazmat .primitives import hashes
11
11
from cryptography .hazmat .primitives .kdf .pbkdf2 import PBKDF2HMAC
12
12
from kivy import Config
13
- from kivy .lang import Builder
14
13
from kivy .properties import ObjectProperty
15
14
from kivy .uix .boxlayout import BoxLayout
16
15
from kivymd .app import MDApp
@@ -60,7 +59,6 @@ def change_screen(self, name):
60
59
class PyPassword (MDApp ):
61
60
"""Main application wrapper."""
62
61
Logger .info ('Application: Building application' )
63
- icon = file ('icon.ico' , 'p' )
64
62
65
63
def __init__ (self , ** kwargs ):
66
64
super ().__init__ (** kwargs )
@@ -93,7 +91,6 @@ def build(self):
93
91
# Change theme (light/dark)
94
92
self .theme_cls .theme_style = 'Light'
95
93
Logger .info (f'Application: Theme style set to { self .theme_cls .theme_style } ' )
96
- return Builder .load_file (file ('PyPassword.kv' , 'p' ))
97
94
98
95
def on_start (self ):
99
96
self .update_passwords ()
@@ -178,7 +175,7 @@ def add_password(self):
178
175
ok_alias = self .validate_input (alias_box , 3 )
179
176
ok_value = self .validate_input (value_box , 6 )
180
177
181
- password_alias = alias_box .text
178
+ password_alias = alias_box .text . capitalize ()
182
179
password_value = value_box .text
183
180
184
181
if ok_alias is True and ok_value is True :
@@ -228,7 +225,7 @@ def copy_password(self, password=None):
228
225
if n is not None :
229
226
to_decrypt = to_decrypt [0 ][0 ]
230
227
if type (to_decrypt ) is bytes :
231
- with open (file (Files .alpha_key ), 'rb' ) as f :
228
+ with open (appdata (Files .alpha_key ), 'rb' ) as f :
232
229
key = f .read ()
233
230
f = Fernet (key )
234
231
try :
@@ -265,7 +262,9 @@ def del_password(self, password=None):
265
262
Logger .trace ('Called: del_password' )
266
263
267
264
if password is None :
268
- password = self .root .ids .del_password_alias .text
265
+ password = self .root .ids .del_password_alias .text .capitalize ()
266
+
267
+ self .root .ids .del_password_alias .text = ''
269
268
270
269
to_del = query (
271
270
'SELECT `password` FROM `passwords` WHERE `name` LIKE ?;' ,
@@ -307,7 +306,6 @@ def del_password(self, password=None):
307
306
text = 'That password do not exists in database'
308
307
).alert ()
309
308
result_dialog .open ()
310
- self .update_passwords ()
311
309
312
310
def del_password_confirm (self , password ):
313
311
"""This method is called after pressing ``Yes`` in ``del_password`` dialog."""
@@ -327,6 +325,7 @@ def del_password_confirm(self, password):
327
325
]
328
326
)
329
327
result_dialog .open ()
328
+ self .update_passwords ()
330
329
331
330
# ================================
332
331
# Alpha password
@@ -352,24 +351,24 @@ def change_alpha(self, preset=None):
352
351
else :
353
352
password_box .error = False
354
353
try :
355
- open (file (Files .beta_key ))
354
+ open (appdata (Files .beta_key ))
356
355
except FileNotFoundError :
357
356
generate_salt ()
358
357
finally :
359
358
try :
360
- open (file (Files .alpha_key ))
359
+ open (appdata (Files .alpha_key ))
361
360
except FileNotFoundError :
362
- open (file (Files .alpha_key ), 'x' )
361
+ open (appdata (Files .alpha_key ), 'x' )
363
362
finally :
364
- with open (file (Files .beta_key ), 'rb' ) as f :
363
+ with open (appdata (Files .beta_key ), 'rb' ) as f :
365
364
kdf = PBKDF2HMAC (
366
365
algorithm = hashes .SHA256 (),
367
366
length = 32 ,
368
367
salt = f .read (),
369
368
iterations = 100000 ,
370
369
backend = default_backend ()
371
370
)
372
- with open (file (Files .alpha_key ), 'wb' ) as f :
371
+ with open (appdata (Files .alpha_key ), 'wb' ) as f :
373
372
key = base64 .urlsafe_b64encode (kdf .derive (password .encode ()))
374
373
f .write (key )
375
374
Logger .info ('Passwords: Alpha password has changed' )
@@ -562,15 +561,14 @@ def validate_input(self, instance, length):
562
561
if __name__ == '__main__' :
563
562
kivy .require ('1.11.1' )
564
563
565
- Config .set ('kivy' , 'window_icon' , file ('icon.ico' , 'p' ))
566
564
Config .set ('kivy' , 'desktop' , 1 )
567
565
Config .set ('kivy' , 'exit_on_esc' , 0 )
568
566
Config .set ('kivy' , 'pause_on_minimize' , 0 )
569
- Config .set ('graphics' , 'resizable' , 0 )
567
+ Config .set ('graphics' , 'resizable' , 1 )
570
568
571
- Config .set ('kivy' , 'log_dir' , file ( './ logs/' , 'p ' ))
572
- Config .set ('kivy' , 'log_enable' , 0 )
573
- Config .set ('kivy' , 'log_level' , 'debug ' )
569
+ Config .set ('kivy' , 'log_dir' , appdata ( f'. { os . sep } logs{ os . sep } ' ))
570
+ Config .set ('kivy' , 'log_enable' , 1 )
571
+ Config .set ('kivy' , 'log_level' , 'error ' )
574
572
Config .set ('kivy' , 'log_maxfiles' , 10 )
575
573
576
574
Config .write ()
0 commit comments