#950 – PasswordBox Allows Entering a Password

You can use a PasswordBox control to allow a user to enter a password.  The PasswordBox looks like a TextBox, but shows a uniform mask character as you type, to hide the characters that you are typing.  By default, this mask character appears as a filled circle.

In the example below, the user can enter a password into the PasswordBox.  As the user enters their password, the characters are shown using the mask character.

    <StackPanel>
        <StackPanel Orientation="Horizontal" Margin="10">
            <Label Content="Password:"/>
            <PasswordBox Name="pwbPassword"
                         Width="150" Margin="5,0"/>
        </StackPanel>
        <Button Content="Show everybody my Password"
                HorizontalAlignment="Center"
                Padding="10,5"
                Click="Button_Click"/>
    </StackPanel>

950-001
You can read the contents of a PasswordBox by reading its Password property.  This property is just a string containing the password that they entered.

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(pwbPassword.Password);
        }

950-002