Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how to get text value from PasswordBox?

I have a PasswordBox. how can I get the input value from the PasswordBox after the input has been finished?

like image 410
5YrsLaterDBA Avatar asked Feb 24 '10 15:02

5YrsLaterDBA


5 Answers

You can get it from the Password property.

like image 103
Klaus Byskov Pedersen Avatar answered Oct 02 '22 15:10

Klaus Byskov Pedersen


You may extract it from Password property:

passwordBox.Password.ToString()
like image 42
Death Zone Avatar answered Oct 02 '22 16:10

Death Zone


You may not want to store the password in clear text in memory, from the msdn doc you should use SecurePassword in order to prevent that.

Example: SecureString myPass = passwordBox.SecurePassword

https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword

like image 43
jiciftw Avatar answered Oct 02 '22 17:10

jiciftw


If using a MaskedTextbox you can use the .text property. For example:

private void btnOk_Click(object sender, EventArgs e)
{
    if ( myMaskedTextbox.Text.Equals(PASSWORD) )
    {
        //do something
    }         

}
like image 33
Roast Avatar answered Oct 02 '22 15:10

Roast


I use below code to get the length of PasswordBox

PasswordVariableName.Password.Length

It will certainly work on wp8

like image 26
Ehtesham Avatar answered Oct 02 '22 15:10

Ehtesham