Skip to content

Fix Get-Credential to not prompt twice when no parameter is specified#2330

Merged
lzybkr merged 1 commit intoPowerShell:masterfrom
daxian-dbw:get-credential
Sep 27, 2016
Merged

Fix Get-Credential to not prompt twice when no parameter is specified#2330
lzybkr merged 1 commit intoPowerShell:masterfrom
daxian-dbw:get-credential

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

Fix #2306

@msftclas
Copy link
Copy Markdown

Hi @daxian-dbw, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Dongbo Wang). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@daxian-dbw
Copy link
Copy Markdown
Member Author

@lzybkr can you please review this PR? Thanks!

Copy link
Copy Markdown
Contributor

@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know it's weird that we rely on the parameter binder to do the prompting if no arguments are passed, but the prompting is done here if there are arguments.

For example, I get the extra prompting:

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

If I don't specify parameters. This isn't the best user experience, but as it is, I'd recommend always using -Message to avoid that extra text.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could merge this with the previous Match.

@daxian-dbw
Copy link
Copy Markdown
Member Author

The Credential parameter set is the default parameter set, and -Credential is the only mandatory parameter in that parameter set, so it's natural that the parameter binder will kick in prompting for the missing mandatory parameter -Credential when no argument is specified.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Sep 21, 2016

Of course - but I'm asking a different question - can we get the same effect of prompting in Get-Credential without relying on the parameter binder?

For example, if we changed the default message/title in Get-Credential, we'd also want a similar change in the parameter binder. I don't think that's obvious or ideal.

But really - I'm just saying we should be seeing the parameter binding prompts when asking the user for a credential. Ever.

@daxian-dbw
Copy link
Copy Markdown
Member Author

Got @lzybkr 's point now. The current change gives inconsistent prompting experience for Get-Credential and Get-Credential -UserName bar. Note that the default caption and message are not displayed for Get-Credential

PS D:\> Get-Credential

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
User:
PS D:\>
PS D:\> Get-Credential -UserName bar

Windows PowerShell credential request.
Password for user bar:

This is because for Get-Credential, the prompting comes from the parameter binder, while the other comes from Host.UI.PromptForCredential. I will update the PR to provide consistent prompting experience.

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Sep 22, 2016

@daxian-dbw Please take a look #2315

@McAndersDK
Copy link
Copy Markdown
Contributor

I approve this fix 👍

But why not move the last writeobject to the try ?

try
{
    Credential = this.Host.UI.PromptForCredential(_title, _message, _userName, string.Empty);
    WriteObject(Credential);
}

@daxian-dbw
Copy link
Copy Markdown
Member Author

daxian-dbw commented Sep 22, 2016

@McAndersDK it's to avoid a very very rare edge case -- WriteObject somehow throws ArgumentException. If that really happens (unlikely), we should allow that exception to propagate and be handled by the engine.

@daxian-dbw
Copy link
Copy Markdown
Member Author

@lzybkr The PR has been updated to address your comments. Please take another look when you have time. Thanks!

@lzybkr lzybkr merged commit 1ea5558 into PowerShell:master Sep 27, 2016
@daxian-dbw daxian-dbw deleted the get-credential branch September 28, 2016 20:07
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

Successfully merging this pull request may close these issues.

5 participants