Add password confirmation in Get-Credential (#12782)

* Add parameter -ReEnterPassword to prompt user to re-enter the password for confirmation

* Add new public overload function PromptForCredential
This commit is contained in:
Shri Ram K S
2020-07-22 19:13:42 +05:00
committed by GitHub
parent 9c396aa0ea
commit a6bd47f031
11 changed files with 329 additions and 79 deletions
@@ -102,4 +102,21 @@ Describe "Get-Credential Test" -Tag "CI" {
$netcred.UserName | Should -Be "John"
$netcred.Password | Should -Be "CredTest"
}
It "Get-credential Joe -ConfirmPassword set to false"{
$cred = $ps.AddScript("Get-Credential Joe -ConfirmPassword:`$false").Invoke() | Select-Object -First 1
$cred | Should -BeOfType System.Management.Automation.PSCredential
$netcred = $cred.GetNetworkCredential()
$netcred.UserName | Should -Be "Joe"
$netcred.Password | Should -Be "This is a test"
$th.ui.Streams.Prompt[-1] | Should -Match "Credential:[^:]+:[^:]+"
}
It "Get-Credential with only -ConfirmPassword" {
$cred = $ps.AddScript("Get-Credential -ConfirmPassword").Invoke() | Select-Object -First 1
$cred | Should -BeOfType System.Management.Automation.PSCredential
$netcred = $cred.GetNetworkCredential()
$netcred.UserName | Should -Be "John"
$netcred.Password | Should -Be "This is a test"
$th.ui.Streams.Prompt[-2] | Should -Match "Credential:[^:]+:[^:]+"
$th.ui.Streams.Prompt[-1] | Should -Match "Credential@[^@]+@[^@]+"
}
}