pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

`CredDelete` requires `Type` even if input object is `<class 'dict'>` from `CredEnumerate`

Open mavaddat opened this issue 4 years ago • 1 comments

Expected behavior and actual behavior.

I would expect win32cred.CredDelete method be capable of deleting a credential from the credential store without Type specification iff the Target input is <class 'dict'> with key 'Type' having a value of type int.

Instead, there is no overloaded win32cred.CredDelete to handle single parameter of credential object as dictionary.

Traceback (most recent call last):
TypeError: CredDelete() missing required argument 'Type' (pos 2)

Steps to reproduce the problem.

Loop through the credential store to find and delete ones added by keyring Python module. Example code:

import keyring
import win32cred

keyring.set_password('system','me','password')

for cred in win32cred.CredEnumerate():
    if cred['Comment']=='Stored using python-keyring':
        win32cred.CredDelete(cred)

Version of Python and pywin32

Package Version
Python 3.9.6
pywin32 302

Work-around

In the example loop above, simply provide the TargetName and Type values as the two arguments to CredDelete.

for cred in win32cred.CredEnumerate():
    if cred['Comment']=='Stored using python-keyring':
        win32cred.CredDelete(cred['TargetName'],cred['Type'])

Possible resolution

It looks like we just need for PyCredDelete to be able to check if the Target is a dictionary object, then extract the Type attribute. https://github.com/mhammond/pywin32/blob/02706451fc65421e6c3ed0d2c39b508af8bc8ba4/win32/src/win32credmodule.cpp#L621

mavaddat avatar Oct 16 '21 01:10 mavaddat

I'd welcome a PR for this.

mhammond avatar Oct 18 '21 00:10 mhammond

Closed by https://github.com/mhammond/pywin32/pull/2198

Avasam avatar Mar 17 '24 02:03 Avasam