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

- 1,148
- 1
- 17
- 31

- 33,370
- 43
- 136
- 210
6 Answers
You may extract it from Password
property:
passwordBox.Password.ToString()

- 46,825
- 13
- 96
- 126

- 171
- 1
- 2
-
6Surrounding your code with an explanation would seriously improve your answer. – zx485 Jan 02 '17 at 01:37
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://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword
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
}
}

- 1,715
- 5
- 24
- 32
I use below code to get the length of PasswordBox
PasswordVariableName.Password.Length
It will certainly work on wp8

- 25
- 5
You have to give a name to your PasswordBox.
<PasswordBox Name="pwdBox"/>
Then you can access the password as plain text in the .xaml.cs
file by using
var plainPassword = pwdBox.password;
I suggest you read this answer to a similar question where you get to know why you mustn't store this property value in any variable.
However, I found in documentation information about SecureString.
When you get the Password property value, you expose the password as plain text in memory. To avoid this potential security risk, use the SecurePassword property to get the password as a SecureString.
Correct me if I am wrong.
Greetings. Jan.

- 19
- 2