-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add password confirmation in Get-Credential #12782
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
Add password confirmation in Get-Credential #12782
Conversation
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Security/security/CredentialCommands.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/internalHostuserInterfacesecurity.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/internalHostuserInterfacesecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
|
@iSazonov Thank you for the feedback. I have made the appropriate changes. Please review. I see the below error message in Linux test. I can see the file is present. What could be casing this issue. |
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Security/security/CredentialCommands.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Security/security/CredentialCommands.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/resources/ConsoleHostUserInterfaceSecurityResources.resx
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Security/security/CredentialCommands.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Security/security/CredentialCommands.cs
Outdated
Show resolved
Hide resolved
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one minor comment.
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
Outdated
Show resolved
Hide resolved
|
@Shriram0908 Please open new issue in PowerShell-Docs repo and add the reference to the PR description. |
|
Re-entering a password is normally done when creating a username/password, but not when using a password to access resources. I am not sure how useful this change is, particularly since it is opt-in via a parameter switch. I would like to get the committee's opinion before accepting the change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting passwords to plain text, leaves multiple immutable string objects in memory, indefinitely. I think it would be better to convert to byte array for comparison, and the byte array values can be zeroed out afterwards. Also you can compare byte array length for early out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PaulHigin Thank you for the review. I have updated the function to use byte array for comparison and have zeroed it in the finally clause. The memory space where the pointer was pointing had a null value between each byte so I had to double the length to use as size. Please review and provide your feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the user should be prompting multiple times for re-entering password in this loop. It is not known if the password was incorrect the first or second time it was entered. So it may be better to exit with error immediately if the confirmation fails, and let the user try again from the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and let the user try again from the beginning.
What is beginning? Go to user or password re-enter?
Add new private function in ConsoleHostUserInterface to compare secure stings Print "Passwords do not match." in red Fix CodeFactor issues
the cmdlet return null if the confirm password does not match uses byte array for comparison of password
Remove byte array comparison method
Co-authored-by: Ilya <darpa@yandex.ru>
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@Shriram0908 Thanks for your contribution! |
|
Thank you @iSazonov and @PaulHigin for your feedback. |
| public abstract PSCredential PromptForCredential( | ||
| string caption, | ||
| string message, | ||
| string userName, | ||
| bool confirmPassword, | ||
| string targetName, | ||
| PSCredentialTypes allowedCredentialTypes, | ||
| PSCredentialUIOptions options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TylerLeonhardt this may be why the PowerShell daily build has been causing CI issues.
There's a new abstract method in the host which has broken me:
An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.
Unhandled exception. System.TypeLoadException: Method 'PromptForCredential' in type 'Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.EditorServicesConsolePSHostUserInterface' from assembly 'Microsoft.PowerShell.EditorServices, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.EditorServicesConsolePSHost..ctor(ILoggerFactory loggerFactory, String name, Version version, PSHost internalHost, ConsoleReadLine readline)
at Microsoft.PowerShell.EditorServices.Services.PowerShell.PowerShellExecutionService.Initialize() in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\PowerShellExecutionService.cs:line 286
at Microsoft.PowerShell.EditorServices.Services.PowerShell.PowerShellExecutionService.RunTopLevelConsumerLoop() in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\PowerShellExecutionService.cs:line 244
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I'll open an issue to track fixing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add new CI for ESS in the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shriram0908 Thanks! It is a question for MSFT team - they could add optional CIs for dependent tools so we could see possible regressions early. It could be on-demand CIs we run before merge.
PR Summary
Get-Credential: Add parameter-ReEnterPasswordto resolve #10625PR Context
By adding
-ReEnterPasswordparameter the user will be prompted to re-enter the password and performs a comparison. If comparison failsnullis returned and user is notified about password mismatch.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.