Password in Text Box


I'm experimenting with a TextBox which I want to input a password. I have set a checkbox below the TextBox which is labelled "Show Password". The code of the checkbox is shown below

    Private Sub m_cbShowPassword_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_cbShowPassword.CheckedChanged
        Me.tbPassword.UseSystemPasswordChar = Not Me.m_cbShowPassword.Checked
    End Sub

As you can see, I cam attempting to show the password or hide it e.g. *********, depending on whether the checkbox is checked or not.

This works fine until I specify a character in the PasswordChar of the TextBox e.g. * or &. If I do this then password is always hidden (either by * or & - in this case).

I'm guessing that using PasswordChar will always hide the password. Is there a way to specify the character used for the password if UseSystemPasswordChar is used?

Who is Participating?
HainKurtConnect With a Mentor Sr. System AnalystCommented:
oops, it should be

Me.tbPassword.PasswordChar = iif(Me.m_cbShowPassword.Checked, "", "*")
HainKurtSr. System AnalystCommented:

Me.tbPassword.UseSystemPasswordChar = iif(Me.m_cbShowPassword.Checked, "", "*")
HainKurtSr. System AnalystCommented:

The UseSystemPasswordChar property has precedence over the PasswordChar property. Whenever the UseSystemPasswordChar is set to true, the default system password character is used and any character set by PasswordChar is ignored.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

CodeCruiserConnect With a Mentor Commented:

UseSystemPasswordChar is boolean right?

One option is to use two textboxes. One with password configuration and one with plain text configuration and switch between them when the check boxes is ticked/unticked.
käµfm³d 👽Connect With a Mentor Commented:
What about simply this:

Me.tbPassword.PasswordChar = If(Me.chkShowPass.Checked, vbNullChar, "*"c)

Open in new window

Then you don't have to fuss with UseSystemPasswordChar. Make sure you initialize the PasswordChar field in the designer though; otherwise it won't show properly on form load.
HainKurtSr. System AnalystCommented:
dont use UseSystemPasswordChar, just set PasswordChar depending on checkbox.checked value...
käµfm³d 👽Commented:
Guess I'm too slow...  : (
IssacJonesAuthor Commented:
Many thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.