@@ -446,42 +446,6 @@ def import_selected(source, res, data):
446446
447447 # Dialog for creating password for the config archive
448448 def create_password_dialog (self ):
449- # Action after closing pswdDialog
450- def pswdDialog_closed (w , response ):
451- if response == 'ok' :
452- with open (f"{ CACHE } /temp_file" , "w" ) as tmp :
453- tmp .write (self .pswdEntry .get_text ())
454- self .save_config ()
455-
456- # Check the password to see if it meets the criteria
457- def check_password (pswdEntry ):
458- password = self .pswdEntry .get_text ()
459- criteria = [
460- (len (password ) < 12 , "The password is too short. It should has at least 12 characters" ),
461- (not re .search (r'[A-Z]' , password ), "The password should has at least one capital letter" ),
462- (not re .search (r'[a-z]' , password ), "The password should has at least one lowercase letter" ),
463- (not re .search (r'[-_@.:,+=]' , password ), "The password should has at least one special character" ),
464- (" " in password , "The password must not contain spaces" )
465- ]
466-
467- for condition , message in criteria :
468- if condition :
469- self .pswdDialog .set_response_enabled ("ok" , False )
470- print (message )
471- return
472-
473- self .pswdDialog .set_response_enabled ("ok" , True )
474-
475- # Generate Password
476- def pswd_generator (w ):
477- safe = "-_@.:,+="
478- allc = safe + string .ascii_letters + string .digits
479- password = [random .choice (safe ), random .choice (string .ascii_letters ), random .choice (string .digits )] + \
480- [random .choice (allc ) for _ in range (21 )]
481- random .shuffle (password )
482- password = '' .join (password )
483- self .pswdEntry .set_text (password )
484-
485449 # Dialog itself
486450 self .pswdDialog = Adw .AlertDialog .new ()
487451 self .pswdDialog .set_heading (_ ("Create new password" ))
@@ -491,34 +455,64 @@ def pswd_generator(w):
491455 self .pswdDialog .add_response ("ok" , _ ("Apply" ))
492456 self .pswdDialog .set_response_enabled ("ok" , False )
493457 self .pswdDialog .set_response_appearance ('ok' , Adw .ResponseAppearance .SUGGESTED )
494- self .pswdDialog .connect ('response' , pswdDialog_closed )
458+ self .pswdDialog .connect ('response' , self . _pswdDialog_closed )
495459 self .pswdDialog .present ()
496460
497461 # Button for generating strong password
498462 self .pswdgenButton = Gtk .Button .new_from_icon_name ("dialog-password-symbolic" )
499463 self .pswdgenButton .set_tooltip_text (_ ("Generate Password" ))
500464 self .pswdgenButton .add_css_class ("flat" )
501465 self .pswdgenButton .set_valign (Gtk .Align .CENTER )
502- self .pswdgenButton .connect ("clicked" , pswd_generator )
466+ self .pswdgenButton .connect ("clicked" , self . _get_generated_password )
503467
504468 # entry for entering password
505469 self .pswdEntry = Adw .PasswordEntryRow .new ()
506470 self .pswdEntry .set_title (_ ("Password" ))
507- self .pswdEntry .connect ('changed' , check_password )
471+ self .pswdEntry .connect ('changed' , self . _check_password )
508472 self .pswdEntry .add_suffix (self .pswdgenButton )
509473 self .pswdDialog .set_extra_child (self .pswdEntry )
510474
511- # dialog for entering password of the archive
512- def check_password_dialog (self ):
513- # action after closing dialog for checking password
514- def checkDialog_closed (w , response ):
515- if response == 'ok' :
516- self .checkDialog .set_response_enabled ("ok" , False )
517- with open (f"{ CACHE } /temp_file" , "w" ) as tmp :
518- tmp .write (self .checkEntry .get_text ())
475+ # Action after closing pswdDialog
476+ def _pswdDialog_closed (self , w , response ):
477+ if response == 'ok' :
478+ with open (f"{ CACHE } /temp_file" , "w" ) as tmp :
479+ tmp .write (self .pswdEntry .get_text ())
480+ self .save_config ()
481+
482+ # Check the password to see if it meets the criteria
483+ def _check_password (self , pswdEntry ):
484+ password = self .pswdEntry .get_text ()
485+ criteria = [
486+ (len (password ) < 12 , "The password is too short. It should has at least 12 characters" ),
487+ (not re .search (r'[A-Z]' , password ), "The password should has at least one capital letter" ),
488+ (not re .search (r'[a-z]' , password ), "The password should has at least one lowercase letter" ),
489+ (not re .search (r'[-_@.:,+=]' , password ), "The password should has at least one special character" ),
490+ (" " in password , "The password must not contain spaces" )
491+ ]
492+
493+ for condition , message in criteria :
494+ if condition :
495+ self .pswdDialog .set_response_enabled ("ok" , False )
496+ print (message )
497+ return
519498
520- self .import_config ( )
499+ self .pswdDialog . set_response_enabled ( "ok" , True )
521500
501+ # Generate Password
502+ def _get_generated_password (self , w ):
503+ self .password = self ._password_generator ()
504+ self .pswdEntry .set_text (self .password )
505+
506+ def _password_generator (self ):
507+ safe = "-_@.:,+="
508+ allc = safe + string .ascii_letters + string .digits
509+ password = [random .choice (safe ), random .choice (string .ascii_letters ), random .choice (string .digits )] + \
510+ [random .choice (allc ) for _ in range (21 )]
511+ random .shuffle (password )
512+ return '' .join (password )
513+
514+ # dialog for entering password of the archive
515+ def check_password_dialog (self ):
522516 # Dialog itself
523517 self .checkDialog = Adw .AlertDialog .new ()
524518 self .checkDialog .set_heading (_ ("Unlock the archive with a password" ))
@@ -527,13 +521,22 @@ def checkDialog_closed(w, response):
527521 self .checkDialog .add_response ("cancel" , _ ("Cancel" ))
528522 self .checkDialog .add_response ("ok" , _ ("Apply" ))
529523 self .checkDialog .set_response_appearance ('ok' , Adw .ResponseAppearance .SUGGESTED )
530- self .checkDialog .connect ('response' , checkDialog_closed )
524+ self .checkDialog .connect ('response' , self . _checkDialog_closed )
531525 self .checkDialog .present ()
532526
533527 self .checkEntry = Adw .PasswordEntryRow .new ()
534528 self .checkEntry .set_title (_ ("Password" ))
535529 self .checkDialog .set_extra_child (self .checkEntry )
536530
531+ # action after closing dialog for checking password
532+ def _checkDialog_closed (self , w , response ):
533+ if response == 'ok' :
534+ self .checkDialog .set_response_enabled ("ok" , False )
535+ with open (f"{ CACHE } /temp_file" , "w" ) as tmp :
536+ tmp .write (self .checkEntry .get_text ())
537+
538+ self .import_config ()
539+
537540 # Save configuration
538541 def save_config (self ):
539542 self .archive_mode = "--create"
0 commit comments