my password is shown when i enter in password textbox

master_2013

Active member
Joined
Jul 8, 2013
Messages
41
Programming Experience
Beginner

my password is fully shown what i typed not in asterisk when i enter in password text box please help me that it shows in "********" not as "abcde"

here is my code for log in form


Imports System.Data.OleDb

Public Class LOGIN

    Dim conn As New OleDbconnection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Then Exit Sub

        Dim SqlQury As String = "select * FROM LOGON WHERE UserName= '" & Me.TextBox1.Text & "' AND Password= '" & Me.TextBox2.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlQury, conn)

        Dim rdr As OleDbDataReader = cmd.ExecuteReader

        rdr.Read()
        If rdr.HasRows = True Then
            Dim UserName As String = rdr("UserName").ToString
            Dim Password As String = rdr("Password").ToString


            WELCOME.Show()
            Me.Hide()
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox2.PasswordChar = "*"
            TextBox2.MaxLength = 14

        Else
            MessageBox.Show("Invalid Username or Password", "Please Enter Correct Combination", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub frm_login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim cnString As String

        cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Gym.mdb"

        'Create connection
        conn = New OleDbConnection(cnString)

        Try
            ' Open connection
            conn.Open()
        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "Error..", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            ' Close connection
            'conn.Close()
        End Try
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub


whats wrong with it
 
Last edited by a moderator:
You're setting the PasswordChar of the TextBox in the Click event handler of Button1, so your password will not be masked until you click that Button. The logical thing to do is to set the PasswordChar property in the designer. You should always be setting control properties in the designer if you want those property values to apply when the form first opens.
 

my password is fully shown what i typed not in asterisk when i enter in password text box please help me that it shows in "********" not as "abcde"

here is my code for log in form


Imports System.Data.OleDb

Public Class LOGIN

    Dim conn As New OleDbconnection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Then Exit Sub

        Dim SqlQury As String = "select * FROM LOGON WHERE UserName= '" & Me.TextBox1.Text & "' AND Password= '" & Me.TextBox2.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlQury, conn)

        Dim rdr As OleDbDataReader = cmd.ExecuteReader

        rdr.Read()
        If rdr.HasRows = True Then
            Dim UserName As String = rdr("UserName").ToString
            Dim Password As String = rdr("Password").ToString


            WELCOME.Show()
            Me.Hide()
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox2.PasswordChar = "*"
            TextBox2.MaxLength = 14

        Else
            MessageBox.Show("Invalid Username or Password", "Please Enter Correct Combination", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub frm_login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim cnString As String

        cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Gym.mdb"

        'Create connection
        conn = New OleDbConnection(cnString)

        Try
            ' Open connection
            conn.Open()
        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "Error..", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            ' Close connection
            'conn.Close()
        End Try
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub


whats wrong with it

Hello,

Keep TextBox2.PasswordChar = "*" in your form load event. that will solve your problem

Regards,
 
Hello,

Keep TextBox2.PasswordChar = "*" in your form load event. that will solve your problem

Regards,

Or, even better, set it in the designer. Why set any form or control properties in code when you know exactly what they should be at design time? You should only use code to set them if you can't get their value until run time.
 
Back
Top