ARTICLE

Retrieving user password and email address from database in ASP.NET using VB.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET June 14, 2011
Here, we will see how to retrieve user password and email address from database in ASP.NET.
Download Files:
 
Reader Level:

Here, we will see how to retrieve user password and email address from database in ASP.NET. To perform this task We will create a table and stored procedure in a SQL database.

Step 1:

Create Table

Now create a table in a SQL Server database with user name, user password and email fields. The table looks like this.

create table tab

(

      userName varchar(20) not null,

      userPassword varchar(20),

      Email varchar(100)

) 

Now enter some values in the table.

insert into tab values('Rohatash','roh','rohatash.mca@gmail.com');

go

insert into tab values('monu','mohan','monu.rathor@gmail.com');

go

insert into tab values('satendra','satya','Satya@gmail.com');

Now using select statement.

select * from tab;

OUTPUT

table1.gif

Figure1

Step 2:

Create stored procedure

Now create a stored procedure for tab table. That means
user password and email will be retrieve from table using the stored procedure. The stored procedure looks like:

create procedure retriveUserPass

@userName varchar(20)

as

begin

 select userPassword,Email from tab where userName=@userName

end

Step 3:

Create form in asp. net for retrieve user password and email. The form looks like the following figure.

form1.gif

Figure2

Now double-click on the Get Password button and add following code.

Dim strcon As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"

        Dim con As New SqlConnection(strcon)

        Dim com As New SqlCommand("retriveUserPass ", con)

        com.CommandType = CommandType.StoredProcedure

        Dim p1 As New SqlParameter("@userName", TextBoxusername.Text)

        com.Parameters.Add(p1)

        con.Open()

        Dim dr As SqlDataReader = com.ExecuteReader()

 

        If dr.Read() Then

 

            Label1.Text = "Password is: " & dr(0).ToString()

        Else

            Label1.Text = "User Name does not exist"

        End If

        con.Close()

Now double click on the Get Email button and add following code.          

Dim strcon As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"

        Dim con As New SqlConnection(strcon)

        Dim com As New SqlCommand("retriveUserPass ", con)

        com.CommandType = CommandType.StoredProcedure

        Dim p1 As New SqlParameter("@userName", TextBoxusername.Text)

        com.Parameters.Add(p1)

        con.Open()

        Dim dr As SqlDataReader = com.ExecuteReader()

        If dr.Read() Then

            Label1.Text = "Password is: " & dr(1).ToString()

        Else

            Label1.Text = "User Name does not exist"

        End If

        con.Close()

 

Step 4:

Now run the application and enter the username which is not defined in table and click on any button.

form2.gif

Figure3

Now enter the the username which is entered in the table and click on the Get Password button to get password.

cform3.gif

Figure4

Now enter the the username which is entered in the table and click on the Get Email button to get email.

cform4.gif

Figure5

You can also download the attachment and test it yourself.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor