コード例 #1
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     key = username + '@' + service
     wallet = open_kwallet()
     if wallet is None:
         # the user pressed "cancel" when prompted to unlock their keyring.
         raise PasswordDeleteError("Cancelled by user")
     if wallet.keyDoesNotExist(wallet.walletName(), 'Python', key):
         raise PasswordDeleteError("Password not found")
     wallet.removeEntry(key)
コード例 #2
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     items = self._find_passwords(service, username, deleting=True)
     if not items:
         raise PasswordDeleteError("Password not found")
     for current in items:
         result = GnomeKeyring.item_delete_sync(current.keyring,
                                                current.item_id)
         if result == GnomeKeyring.Result.CANCELLED:
             raise PasswordDeleteError("Cancelled by user")
         elif result != GnomeKeyring.Result.OK:
             raise PasswordDeleteError(result.value_name)
コード例 #3
0
ファイル: SecretService.py プロジェクト: LLNL/GRAPE
 def delete_password(self, service, username):
     """Delete the stored password (only the first one)
     """
     collection = self.get_default_collection()
     items = collection.search_items(
         {"username": username, "service": service})
     for item in items:
         return item.delete()
     raise PasswordDeleteError("No such password!")
コード例 #4
0
ファイル: Windows.py プロジェクト: LLNL/GRAPE
 def delete_password(self, service, username):
     compound = self._compound_name(username, service)
     deleted = False
     for target in service, compound:
         existing_pw = self._get_password(target)
         if existing_pw and existing_pw['UserName'] == username:
             deleted = True
             self._delete_password(target)
     if not deleted:
         raise PasswordDeleteError(service)
コード例 #5
0
ファイル: Windows.py プロジェクト: LLNL/GRAPE
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     try:
         key_name = r'Software\%s\Keyring' % service
         hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
             winreg.KEY_ALL_ACCESS)
         winreg.DeleteValue(hkey, username)
     except WindowsError:
         e = sys.exc_info()[1]
         raise PasswordDeleteError(e)
コード例 #6
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     service = escape_for_ini(service)
     config = configparser.RawConfigParser()
     if os.path.exists(self.file_path):
         config.read(self.file_path)
     if not config.remove_section(service):
         raise PasswordDeleteError("Password not found")
     # update the file
     config_file = open(self.file_path, 'w')
     config.write(config_file)
コード例 #7
0
    def _find_passwords(self, service, username, deleting=False):
        """Get password of the username for the service
        """
        passwords = []

        service = self._safe_string(service)
        username = self._safe_string(username)
        for attrs_tuple in (('username', 'service'), ('user', 'domain')):
            attrs = GnomeKeyring.Attribute.list_new()
            GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[0],
                                                      username)
            GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[1],
                                                      service)
            result, items = GnomeKeyring.find_items_sync(
                GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
            if result == GnomeKeyring.Result.OK:
                passwords += items
            elif deleting:
                if result == GnomeKeyring.Result.CANCELLED:
                    raise PasswordDeleteError("Cancelled by user")
                elif result != GnomeKeyring.Result.NO_MATCH:
                    raise PasswordDeleteError(result.value_name)
        return passwords
コード例 #8
0
ファイル: OS_X.py プロジェクト: LLNL/GRAPE
 def delete_password(self, service, username):
     del_error = PasswordDeleteError("Can't delete password in keychain")
     if username is None:
         username = ''
     try:
         cmd = [
             'security',
             SecurityCommand('delete', self.store),
             '-a',
             username,
             '-s',
             service,
         ]
         # set up the call for security.
         call = subprocess.Popen(cmd,
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
         stdoutdata, stderrdata = call.communicate()
         code = call.returncode
         # check return code.
         if code is not 0:
             raise del_error
     except:
         raise del_error