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

Error verifying credential with domain name in user #3

Open
cashfoley opened this issue Aug 21, 2013 · 1 comment
Open

Error verifying credential with domain name in user #3

cashfoley opened this issue Aug 21, 2013 · 1 comment

Comments

@cashfoley
Copy link

I got an exception when creating a credential using a domanname\user

This is what worked for me

function setCredential {
param(
[parameter(mandatory=$true,position=0)]
[string] $keyName,
[parameter(mandatory=$true,position=1,parametersetname="UsernamePassword")]
[string] $username,
[parameter(mandatory=$true,position=2,parametersetname="UsernamePassword")]
[string] $password,
[parameter(mandatory=$true,position=1,parametersetname="PSCredential")]
[System.Management.Automation.PSCredential] $credential,
$cert,
$store = (gi .)
)
if( $cert -eq $null ) {
$cert = selectCertificate
}

if( $credential -ne $null ) {
    $networkcredential = $credential.GetNetworkCredential()
    $username = $credential.Username
    $password = $networkcredential.Password
}

if( !($username -and $password) ) {
    throw "Must specify credential or non-empty username+password"
    return
}

if( $cert.GetType().Name -eq "String" ) {
    $cert = ls cert:\CurrentUser\My | ?{ $_.Subject -match $cert } | select -first 1
}
sc -Encoding Ascii -Path (keyFilePath $store $keyName) -Value @( $cert.Thumbprint, (PKCSEncrypt "${username}:${password}" $cert) )

$TestCred = getCredential -keyName $keyName -store $store
$TestNetcred = $TestCred.GetNetworkCredential()
if( $TestCred.Username -ne $username -or $TestNetcred.Password -ne $password ) {
    throw "Failed to encrypt credential"
}

}

The problem is the NetworkCredential puts the domain in a different Field. You need to get the username from the PSCredential and the password from the NetworkCredential

Sorry... never used git so I didn't contribute. LOL. great code otherwise

@anderssonjohan
Copy link
Contributor

Yes - it is designed for non domain environments.
Would you mind forking the repo and commit your changes and submit a pull request?

Thanks in advance!

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

2 participants