locked
simple question, how to vhange the textbox value to pasword mode RRS feed

  • Question

  • User123544528 posted

    hi

    (vb.net) Im reading value username from textbox1 and if user exists then writing the same user password into another textbox i.e: textbox2, but i want the value which retreving from database should be in password mode, such as ****,

    if im setting TextBox2.TextMode = TextBoxMode.Password, then it is not showing any thing in

    textbox2, if im not usingpassword mode then it is showing value but not in password mode


    this my code:

    Protected Sub button1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim strconnection As OleDbConnection
            Dim mydataset As New DataSet
            Dim sql As OleDbCommand
            Dim dr As OleDbDataReader
            strconnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0;Data SOurce=E:\WebSite31\anil.mdb")
            strconnection.Open()
            sql = New OleDbCommand("select * from anil where name ='" & TextBox1.Text & "'", strconnection)
            dr = sql.ExecuteReader()
            If dr.Read() Then
                Response.Write("Valid user")
                TextBox2.Text = dr(3)
                TextBox2.TextMode = TextBoxMode.Password
                TextBox2.Text = Visible
            Else
                Response.Write("Invalid user")
    
            End If
        End Sub


    when it retrieve the value from databse, i want textbox2.text to be password mode

    please help

    Friday, May 14, 2010 1:41 AM

Answers

  • User-821857111 posted

    It's not a good idea to set the value of a password box like this at all, which is maybe why setting the Text property doesn't work. I could just enter any random name into your form, and if there is a match, you will present me with a password.

    However, if you really want to set the value, you can do it like this:

    TextBox2.Attributes.Add("value", dr[3])

    By the way, I will always get a password from your current code without having to guess by using Sql Injection. You should use parameters: Parameter Queries in ASP.NET with MS Access


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 14, 2010 3:31 AM

All replies

  • User-821857111 posted

    It's not a good idea to set the value of a password box like this at all, which is maybe why setting the Text property doesn't work. I could just enter any random name into your form, and if there is a match, you will present me with a password.

    However, if you really want to set the value, you can do it like this:

    TextBox2.Attributes.Add("value", dr[3])

    By the way, I will always get a password from your current code without having to guess by using Sql Injection. You should use parameters: Parameter Queries in ASP.NET with MS Access


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 14, 2010 3:31 AM
  • User123544528 posted

    thank u very much

    but in vb.net, use () instead of []

    TextBox2.Attributes.Add("value", dr(3))

    Friday, May 14, 2010 3:44 AM
  • User-821857111 posted

    but in vb.net, use () instead of []

    At least I remembered to remove the semi-colon Wink


    Friday, May 14, 2010 8:53 AM