[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Password in Text Box

Posted on 2011-10-26
8
Medium Priority
?
325 Views
Last Modified: 2012-05-12
Hi

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?

Issac
0
Comment
Question by:IssacJones
8 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 37031052
try

Me.tbPassword.UseSystemPasswordChar = iif(Me.m_cbShowPassword.Checked, "", "*")
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 336 total points
ID: 37031061
oops, it should be

Me.tbPassword.PasswordChar = iif(Me.m_cbShowPassword.Checked, "", "*")
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 37031068
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.usesystempasswordchar.aspx

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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 332 total points
ID: 37031071
@HainKurt

UseSystemPasswordChar is boolean right?

@IssacJones
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.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 332 total points
ID: 37031080
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.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 37031084
dont use UseSystemPasswordChar, just set PasswordChar depending on checkbox.checked value...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37031086
Guess I'm too slow...  : (
0
 

Author Closing Comment

by:IssacJones
ID: 37031143
Many thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question