Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

showing password characters on some event for passwordbox

I am developing a windows phone application.In that i ask the user to login.

On the login page the user has to enter password.

Now what I want is that i give user a check box which when selected should show the characters of the password.

I have not seen any property on password box to show password characters.

Please suggest some way to do it.

like image 574
rakesh Avatar asked Apr 10 '12 15:04

rakesh


People also ask

How can I see my password in password box?

By default, the password reveal button (or "peek" button) is shown. The user must continuously press the button to view the password, so that a high level of security is maintained.

What is the password box?

A password box is a text input box that conceals the characters typed into it for the purpose of privacy. A password box looks like a text box, except that it renders placeholder characters in place of the text that has been entered.


1 Answers

Don't think that is possible with PasswordBox... just a thought, but you might accomplish the same result using a hidden TextBox and when the user clicks the CheckBox, you just hide the PasswordBox and show the TextBox; if he clicks again, you switch their Visibility state again, and so on...

Edit

And here it is how!

Just add a page, change the ContentPanel to a StackPanel and add this XAML code:

<PasswordBox x:Name="MyPasswordBox" Password="{Binding Text, Mode=TwoWay, ElementName=MyTextBox}"/>
<TextBox x:Name="MyTextBox" Text="{Binding Password, Mode=TwoWay, ElementName=MyPasswordBox}" Visibility="Collapsed" />
<CheckBox x:Name="ShowPasswordCharsCheckBox" Content="Show password" Checked="ShowPasswordCharsCheckBox_Checked" Unchecked="ShowPasswordCharsCheckBox_Unchecked" />

Next, on the page code, add the following:

private void ShowPasswordCharsCheckBox_Checked(object sender, RoutedEventArgs e)
{
    MyPasswordBox.Visibility = System.Windows.Visibility.Collapsed;
    MyTextBox.Visibility = System.Windows.Visibility.Visible;

    MyTextBox.Focus();
}

private void ShowPasswordCharsCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
    MyPasswordBox.Visibility = System.Windows.Visibility.Visible;
    MyTextBox.Visibility = System.Windows.Visibility.Collapsed;

    MyPasswordBox.Focus();
}

This works fine, but with a few more work, you can do this fully MVVM'ed!

like image 123
Pedro Lamas Avatar answered Sep 28 '22 06:09

Pedro Lamas