Use value of passwordbox as to a variable

16,364

The SecureString class doesn't allow you to see the value; that's the whole point of it. If you want to be able to work with the value entered into the PasswordBox, use the Password member of PasswordBox instead of the SecurePassword member:

private void loginbutton_Click(object sender, RoutedEventArgs e)
{
    usr = textBox1.Text;
    String pass = textBox2.Password;
}
Share:
16,364
deception1
Author by

deception1

Updated on June 04, 2022

Comments

  • deception1
    deception1 almost 2 years

    i have a password box and i want to get the input data to check for verification.

    My passwordbox c# code

      public void textBox2_TextInput(object sender, TextCompositionEventArgs e)
        {
            //pass = textBox2.ToString();
        }
    

    and the xaml code

    <PasswordBox Name="textBox2" 
                 PasswordChar="*"  
                 TextInput="textBox2_TextInput" />
    

    this is what i have written to capture the password

      private void loginbutton_Click(object sender, RoutedEventArgs e)
       {
           usr = textBox1.Text;
           SecureString passdat =textBox2.SecurePassword;
           pass = passdat.ToString();
       }             
    

    it returns null.This is a dummy demo so no encryption is required.I was using a text box earlier and the verification worked.using a password box just complicated things.