(self)
Change the master key of the database
Change the master key of the database
Change the master key of the database
def change_db_password(self):
        '''Change the master key of the database'''

        if (self.address != "127.0.0.1" and self.address != "localhost" and
            self.remote is True):
            self.control.draw_text(False,
                           (1, 0, "Password change from remote is not "
                                  "allowed"),
                           (3, 0, "Press any key."))
            if self.control.any_key() == -1:
                self.close()

        while True:
            auth = self.control.gen_menu(1, (
                                         (1, 0, 'Use a password (1)'),
                                         (2, 0, 'Use a keyfile (2)'),
                                         (3, 0, 'Use both (3)')))
            if auth == 2 or auth == 3:
                while True:
                    filepath = FileBrowser(self.control, False, True, None)()
                    if filepath == -1:
                        self.close()
                    elif not isfile(filepath):
                        self.control.draw_text(self.changed,
                                               (1, 0, "That's not a file!"),
                                               (3, 0, 'Press any key.'))
                        if self.control.any_key() == -1:
                            self.close()
                        continue
                    break
                if filepath is False:
                    continue
                if self.remote is False:
                    self.db.keyfile = filepath
                else:
                    tmp_keyfile = filepath
                if auth != 3:
                    password = None
                    tmp_password = None

            if auth == 1 or auth == 3:
                password = self.control.get_password('New Password: ')
                if password is False:
                    continue
                elif password == -1:
                    self.close()
                confirm = self.control.get_password('Confirm: ')
                if confirm is False:
                    continue
                elif confirm == -1:
                    self.close()
                if password == confirm:
                    if self.remote is False:
                        self.db.password = password
                    else:
                        tmp_password = password
                else:
                    self.control.draw_text(self.changed,
                                           (1, 0, 'Passwords didn\'t match. '
                                               'Press any key.'))
                    if self.control.any_key() == -1:
                        self.close()
                    continue
                if auth != 3:
                    filepath = None
                    tmp_keyfile = None

            if auth is False:
                return False
            elif auth == -1:
                self.close()
            elif self.remote is True:
                if tmp_password is None:
                    tmp_password = b''
                else:
                    tmp_password = tmp_password.encode()
                if tmp_keyfile is None:
                    tmp_keyfile = b''
                else:
                    tmp_keyfile = tmp_keyfile.encode()

                answer = self.client().change_password(tmp_password, 
                                                       tmp_keyfile)
                if self.check_answer(answer) is False:
                    return False
                else:
                    self.db.password = password
                    self.db.keyfile = filepath
                return True
            else:
                self.changed = True
                return True
def change_db_password ( self ) : if ( self . address != "127.0.0.1" and self . address != "localhost" and self . remote is True ) : self . control . draw_text ( False , ( 1 , 0 , "Password change from remote is not " "allowed" ) , ( 3 , 0 , "Press any key." ) ) if self . control . any_key ( ) == - 1 : self . close ( ) while True : auth = self . control . gen_menu ( 1 , ( ( 1 , 0 , 'Use a password (1)' ) , ( 2 , 0 , 'Use a keyfile (2)' ) , ( 3 , 0 , 'Use both (3)' ) ) ) if auth == 2 or auth == 3 : while True : filepath = FileBrowser ( self . control , False , True , None ) ( ) if filepath == - 1 : self . close ( ) elif not isfile ( filepath ) : self . control . draw_text ( self . changed , ( 1 , 0 , "That's not a file!" ) , ( 3 , 0 , 'Press any key.' ) ) if self . control . any_key ( ) == - 1 : self . close ( ) continue break if filepath is False : continue if self . remote is False : self . db . keyfile = filepath else : tmp_keyfile = filepath if auth != 3 : password = None tmp_password = None if auth == 1 or auth == 3 : password = self . control . get_password ( 'New Password: ' ) if password is False : continue elif password == - 1 : self . close ( ) confirm = self . control . get_password ( 'Confirm: ' ) if confirm is False : continue elif confirm == - 1 : self . close ( ) if password == confirm : if self . remote is False : self . db . password = password else : tmp_password = password else : self . control . draw_text ( self . changed , ( 1 , 0 , 'Passwords didn\'t match. ' 'Press any key.' ) ) if self . control . any_key ( ) == - 1 : self . close ( ) continue if auth != 3 : filepath = None tmp_keyfile = None if auth is False : return False elif auth == - 1 : self . close ( ) elif self . remote is True : if tmp_password is None : tmp_password = b'' else : tmp_password = tmp_password . encode ( ) if tmp_keyfile is None : tmp_keyfile = b'' else : tmp_keyfile = tmp_keyfile . encode ( ) answer = self . client ( ) . change_password ( tmp_password , tmp_keyfile ) if self . check_answer ( answer ) is False : return False else : self . db . password = password self . db . keyfile = filepath return True else : self . changed = True return True