Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test-Credential throws exception #9

Open
jaspain opened this issue May 19, 2018 · 1 comment
Open

Test-Credential throws exception #9

jaspain opened this issue May 19, 2018 · 1 comment
Assignees

Comments

@jaspain
Copy link
Contributor

jaspain commented May 19, 2018

Test-Credential and Find-Credential don’t work as expected. The problem lies with the Find function in CredentialManagement.cs. Because CredWrite alters the names of credentials, you are using the function FixTarget to make this alteration transparent when credentials are retrieved. Thus FixTarget needs to be applied to the filter argument of the Find function to make that transparent as well.

Also in the Find function CredEnumerate returns false when it fails. In addition to some exception-worthy problems, the failure may be due to there being no credentials that pass the filter (ERROR_NOT_FOUND). In the case of ERROR_NOT_FOUND, the Find function should return a null result rather than throwing an exception.

In my pull request, I am proposing changes to the Find function, and based on these changes I also added some additional examples for Test-Credential and Find-Credential.

@Verayth
Copy link

Verayth commented Jul 12, 2018

Not exactly sure if it's the same issue, but with version 4.5, every command I've tried throws an exception. I'm using PSV 5.1.14409.1012 on Windows 7:

[16:45:18][00:00:01.0211021] C:\> Find-Credential | ? username -like *test* | select username
[16:45:23][00:00:00.0050005] C:\> get-credential test -store
Exception calling "Load" with "1" argument(s): "Element not found"
At C:\Program Files\WindowsPowerShell\Modules\BetterCredentials\4.5\BetterCredentials.psm1:351 char:21
+ ...             $Credential = [CredentialManagement.Store]::Load($UserNam ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception


UserName                     Password
--------                     --------
test     System.Security.SecureString


[16:45:40][00:00:01.8001800] C:\> Find-Credential | ? username -like *test* | select username

UserName
--------
test


[16:45:59][00:00:00.0050005] C:\> Find-Credential test
Exception calling "Find" with "1" argument(s): "Element not found"
At C:\Program Files\WindowsPowerShell\Modules\BetterCredentials\4.5\BetterCredentials.psm1:84 char:5
+     [CredentialManagement.Store]::Find($Filter)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception

[16:46:15][00:00:00.0250025] C:\> Test-Credential test
Exception calling "Find" with "1" argument(s): "Element not found"
At C:\Program Files\WindowsPowerShell\Modules\BetterCredentials\4.5\BetterCredentials.psm1:122 char:16
+ ...        return [CredentialManagement.Store]::Find($target).Count -gt 0
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception

[16:46:32][00:00:00.0100010] C:\> Remove-Credential test
Exception calling "Delete" with "3" argument(s): "Element not found"
At C:\Program Files\WindowsPowerShell\Modules\BetterCredentials\4.5\BetterCredentials.psm1:217 char:9
+         [CredentialManagement.Store]::Delete($Target, $Type, $false)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants