0

I see that a PasswordBox control in WPF has the .PasswordChar value this updates the whole PasswordBox to be either a dot or which ever character of choice eg 'X'

What I was interested in seeing I could have different PasswordChar for each key input the user enters, eg

Enter Password: XekelXf2l31

So rather a mask of the same Char and mask made of random Chars or from an Array of my choosing.

I have tried this so far with no luck:

public static string pwString = "XekelXf2l31";
public static char[] pwChars = pwString.ToCharArray();
public int count = 0;

private void PWbox1_KeyUp(object sender, KeyEventArgs e)
    {
        if (count < pwChars.Length)
        {
            PWbox1.PasswordChar = pwChars[count];
            count++;
        }
        else
        {
            count = 0;
            PWbox1.PasswordChar = pwChars[count];
        }
    }

Will I just need to use a standard TextBox?

8WmK
  • 106
  • 1
  • 8
  • Do you want to confuse the uninvited person looking behind your shoulder? Sounds evil haha – MaxB Apr 12 '18 at 10:45
  • this should help you https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c – styx Apr 12 '18 at 10:46
  • The question here is about wpf control, not getting random char – MaxB Apr 12 '18 at 10:48

0 Answers0