(self)
return (password, keyfile)
Get authentication credentials
Get authentication credentials
Get authentication credentials
def get_authentication(self):
        """Get authentication credentials"""

        while True:
            if (self.config['skip_menu'] is False or
                (self.config['rem_db'] is False and
                 self.config['rem_key'] is False)):
                auth = self.gen_menu(1, (
                                     (1, 0, 'Use a password (1)'),
                                     (2, 0, 'Use a keyfile (2)'),
                                     (3, 0, 'Use both (3)')),
                                    (5, 0, 'Press \'F5\' to go back to main '
                                           'menu'))
            else:
                self.draw_text(False)
                auth = 3
            if auth is False:
                return False
            elif auth == -1:
                self.close()
            if auth == 1 or auth == 3:
                if self.config['skip_menu'] is True:
                    needed = False
                else:
                    needed = True
                password = self.get_password('Password: ', needed = needed)
                if password is False:
                    self.config['skip_menu'] = False
                    continue
                elif password == -1:
                    self.close()
                # happens only if self.config['skip_menu'] is True
                elif password == "":
                    password = None
                if auth != 3:
                    keyfile = None
            if auth == 2 or auth == 3:
                # Ugly construct but works
                # "if keyfile is False" stuff is needed to implement the
                # return to previous screen stuff
                # Use similar constructs elsewhere
                while True:
                    self.get_last_key()
                    if (self.last_key is None or
                            self.config['rem_key'] is False):
                        ask_for_lf = False
                    else:
                        ask_for_lf = True

                    keyfile = FileBrowser(self, ask_for_lf, True, 
                                          self.last_key)()
                    if keyfile is False:
                        break
                    elif keyfile == -1:
                        self.close()
                    elif not isfile(keyfile):
                        self.draw_text(False,
                                       (1, 0, 'That\'s not a file'),
                                       (3, 0, 'Press any key.'))
                        if self.any_key() == -1:
                            self.close()
                        continue
                    break
                if keyfile is False:
                    continue
                if auth != 3:
                    password = None
                if self.config['rem_key'] is True:
                    if not isdir(self.key_home[:-4]):
                        if isfile(self.key_home[:-4]):
                            remove(self.key_home[:-4])
                        makedirs(self.key_home[:-4])
                    handler = open(self.key_home, 'w')
                    handler.write(keyfile)
                    handler.close()
            break
        return (password, keyfile)
def get_authentication ( self ) : while True : if ( self . config [ 'skip_menu' ] is False or ( self . config [ 'rem_db' ] is False and self . config [ 'rem_key' ] is False ) ) : auth = self . gen_menu ( 1 , ( ( 1 , 0 , 'Use a password (1)' ) , ( 2 , 0 , 'Use a keyfile (2)' ) , ( 3 , 0 , 'Use both (3)' ) ) , ( 5 , 0 , 'Press \'F5\' to go back to main ' 'menu' ) ) else : self . draw_text ( False ) auth = 3 if auth is False : return False elif auth == - 1 : self . close ( ) if auth == 1 or auth == 3 : if self . config [ 'skip_menu' ] is True : needed = False else : needed = True password = self . get_password ( 'Password: ' , needed = needed ) if password is False : self . config [ 'skip_menu' ] = False continue elif password == - 1 : self . close ( ) # happens only if self.config['skip_menu'] is True elif password == "" : password = None if auth != 3 : keyfile = None if auth == 2 or auth == 3 : # Ugly construct but works # "if keyfile is False" stuff is needed to implement the # return to previous screen stuff # Use similar constructs elsewhere while True : self . get_last_key ( ) if ( self . last_key is None or self . config [ 'rem_key' ] is False ) : ask_for_lf = False else : ask_for_lf = True keyfile = FileBrowser ( self , ask_for_lf , True , self . last_key ) ( ) if keyfile is False : break elif keyfile == - 1 : self . close ( ) elif not isfile ( keyfile ) : self . draw_text ( False , ( 1 , 0 , 'That\'s not a file' ) , ( 3 , 0 , 'Press any key.' ) ) if self . any_key ( ) == - 1 : self . close ( ) continue break if keyfile is False : continue if auth != 3 : password = None if self . config [ 'rem_key' ] is True : if not isdir ( self . key_home [ : - 4 ] ) : if isfile ( self . key_home [ : - 4 ] ) : remove ( self . key_home [ : - 4 ] ) makedirs ( self . key_home [ : - 4 ] ) handler = open ( self . key_home , 'w' ) handler . write ( keyfile ) handler . close ( ) break return ( password , keyfile )