Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(VB.net )
hi, im using DAL and BLL, here i want to check whether user exists(Textbox1) or not, if user exists then write the users password from Db to Textbox2 and textbox2 text mode should be password.
here is my code:

C++
Protected Sub button1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


C++
Dim productslogic As New productsBLL()

VB
GridView1.DataSource = productslogic.GetDataByname(TextBox1.Text)
GridView1.DataBind()


VB
Dim mydataset As New DataSet
  Dim strconnection As SqlConnection
  strconnection = New SqlConnection(ConfigurationManager.ConnectionStrings("masterConnectionString").ConnectionString)
  strconnection.Open()
  Dim myData As New SqlDataAdapter("select * from asaa where name='" & TextBox1.Text & "'   ", strconnection)
  Dim dr As SqlDataReader
  myData.TableMappings.Add("Table", "ak")
  myData.Fill(mydataset)
  GridView1.DataSource = mydataset.Tables(0).DefaultView
  GridView1.DataBind()
  TextBox2.TextMode = TextBoxMode.Password
  TextBox2.Text = mydataset.Tables(0).Rows(1)(1).ToString()


please tell me how to retrieve the password to textbox2 if user exists.
i dont want to use connection directly dataset or dataadapter should use BLL
C++
please help with some code
Posted
Comments
OriginalGriff 14-May-10 8:03am    
First off, don't access your DB like that - Google for "SQL Injection Attack" for details as to why not. Use SqlCommand.AddWithValue instead.
Secondly, don't store passwords in your DB in clear text. Store encrypted, or hashed instead.
Combine your two faults together, and any user can read out everyone's passwords with no permissions needed!

hello,
why to make the query so complex dear just have 2 textbox and you are done

hers your code but i still don't get it why you want the password to appear on textbox2 as it may harm the applications security anyways her's your code also you wana set the textbox2 mode to password so whats the use

Explanation: I have not used datagrid as this can be done without datagrid and please encrypt your password and then save them to database
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True")
        con.Open()
        Dim query As String = "select pass from mytable where user1='" + TextBox1.Text + "'"

        Dim cmd As SqlCommand = New SqlCommand(query, con)
        Dim da As SqlDataReader = cmd.ExecuteReader()
        If (da.Read() = True) Then
            TextBox2.Text = da(0).ToString()
            TextBox2.UseSystemPasswordChar = True
        Else
            MessageBox.Show("Database scan complete no such user found")

        End If

        con.Close()
        con.Dispose()
    End Sub
End Class


Do rate my answer once you find it useful
Thanks & Regards
Radix :)
 
Share this answer
 
Comments
Anil Sarda 15-May-10 1:28am    
thank u for the code, but i dont want to use dataconnections,
data connections should be done by using DAL and BLL
thats wat im looking for?
You can't set the text for a password textbox.
 
Share this answer
 
Comments
Anil Sarda 14-May-10 9:05am    
ok, but how to write gridview to the textbox
[no name] 14-May-10 9:33am    
Write gridview to textbox? This makes no sense at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900