Another way is with the Read-Host commandlet. If you ask it to return a SecureString
, it will show a password field (as a modal dialog in Sitecore Powershell). You then have to convert the so-called secure string back into a normal string to validate credentials:
(Update: use NetworkCredential class to get clear password.)
$username = [Sitecore.Context]::User.Name
$securePass = Read-Host -Prompt 'Please enter your password' -AsSecureString
$password = (New-Object System.Net.NetworkCredential "", $securePass).Password
$isValid = [System.Web.Security.Membership]::ValidateUser($username, $password)
One issue with this method is you can't control the dialog's title. But it's a quick fix.
Update: yet another (IMO better) way using Read-Variable, which sets a regular string and provides more control:
$username = [Sitecore.Context]::User.Name
$password = '' # Clear password var so there's no initial value
Read-Variable -Parameters @{Name="password"; Title="Password"; Editor="Password"} `
-Description 'Please enter your password to confirm' `
-Title 'Confirmation' | Out-Null
$isValid = [System.Web.Security.Membership]::ValidateUser($username, $password)