473,486 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem in Retriveing Data from Database for Authentecation

Hi EveryBody:

I made web site using asp.net 2.0 Vb.Net. The project depends on database in
the local machine. The web site has
• Create User Wizard and
• Login form
When the user is created the username and password saved in the database.
And the code is as follows:

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e
As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim husam As String = CreateUserWizard1.UserName
Dim password As String = CreateUserWizard1.Password
Dim cmd As SqlCommand
Dim connectionString As String = "Integrated Security=SSPI;" +
"Initial Catalog=Husam;" + "Data Source=localhost;"
Dim connection As New SqlConnection(connectionString)
Dim sql As String
Try
connection.Open()
sql = "INSERT INTO husam_Tab(user_Name,user_Password)" +
"Values('" & husam & "','" & password & "')"
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
End Try
End Sub

But I face problem when I retrieve the username and password from the
database to perform the authentication in the login form. The login form
retrieves the data saved in the App_Data File in the solution not from the
database.

The code for retrieving data from database as follows:

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim husam As String = Login1.UserName
Dim password As String = Login1.Password
Dim cmd As SqlCommand
Dim connectionString As String = "Integrated Security=SSPI;" +
"Initial Catalog=Husam;" + "Data Source=localhost;"
Dim connection As New SqlConnection(connectionString)
Dim sql As String
Dim rawan As New List(Of String)
Dim rawan1 As New List(Of String)
Try
connection.Open()
sql = "SELECT user_Name,user_Password FROM husam_Tab"
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
While (myReader.Read())
rawan.Add(myReader.GetString(0))
rawan1.Add(myReader.GetString(1))
End While
myReader.Close()
connection.Close()
If rawan.Contains(husam) Then
If rawan1.Contains(password) Then
'Login1.DestinationPageUrl = ""
Else
Login1.FailureText = "Your password is not correct"
Login1.FailureAction = LoginFailureAction.Refresh
End If
Else
MsgBox("Your user name is not correct")
End If
Catch ex As Exception
End Try
End Sub

So any help or redirection to make the authentication from the database not
from the App_Data will be appreciated.

Regard’s

Husam

May 20 '07 #1
1 2573
From your code, it appears you are using custom code with the ASP.NET bits.
If so, you should create a custom provider and use the model supplied for
you by Microsoft. Either that or you should create all of your own controls,
as a half-baked solution is often worse than a badly desinged solution.

The .NET bits will handle all insert, update, delete and even authentication
and do it through very simple code. If you are circumventing the way the
provider works (as you are), you are half building the solution, as you are
removing the best bits.

The custom provider model allows you to alter the schema, database type and
even the methodology (to an extent) without changing the way it works. THis
means you can show somebody the plethora of material on the web and they can
use your model. When you circumvent all of the methods, as you have done,
you are on your own.

To get to the database, you probably just have to change your connection
string in the web.config file. But, I would seriously consider creating a
custom provider so you do not have to circumvent methods.

NOTE: When you circumvent methods, you generally have to send a false back
out for the authenticated boolean value. If not, the provider will still do
a normal authenticate, as it assumes everything checks out for it to do its
job. Read the documentation on all of the methods you are circumventing,
otehrwise, all of your work might be for naught.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"Husam" <Hu***@discussions.microsoft.comwrote in message
news:05**********************************@microsof t.com...
Hi EveryBody:

I made web site using asp.net 2.0 Vb.Net. The project depends on database
in
the local machine. The web site has
. Create User Wizard and
. Login form
When the user is created the username and password saved in the database.
And the code is as follows:

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal
e
As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim husam As String = CreateUserWizard1.UserName
Dim password As String = CreateUserWizard1.Password
Dim cmd As SqlCommand
Dim connectionString As String = "Integrated Security=SSPI;" +
"Initial Catalog=Husam;" + "Data Source=localhost;"
Dim connection As New SqlConnection(connectionString)
Dim sql As String
Try
connection.Open()
sql = "INSERT INTO husam_Tab(user_Name,user_Password)" +
"Values('" & husam & "','" & password & "')"
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
End Try
End Sub

But I face problem when I retrieve the username and password from the
database to perform the authentication in the login form. The login form
retrieves the data saved in the App_Data File in the solution not from the
database.

The code for retrieving data from database as follows:

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.AuthenticateEventArgs) Handles
Login1.Authenticate
Dim husam As String = Login1.UserName
Dim password As String = Login1.Password
Dim cmd As SqlCommand
Dim connectionString As String = "Integrated Security=SSPI;" +
"Initial Catalog=Husam;" + "Data Source=localhost;"
Dim connection As New SqlConnection(connectionString)
Dim sql As String
Dim rawan As New List(Of String)
Dim rawan1 As New List(Of String)
Try
connection.Open()
sql = "SELECT user_Name,user_Password FROM husam_Tab"
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
While (myReader.Read())
rawan.Add(myReader.GetString(0))
rawan1.Add(myReader.GetString(1))
End While
myReader.Close()
connection.Close()
If rawan.Contains(husam) Then
If rawan1.Contains(password) Then
'Login1.DestinationPageUrl = ""
Else
Login1.FailureText = "Your password is not correct"
Login1.FailureAction = LoginFailureAction.Refresh
End If
Else
MsgBox("Your user name is not correct")
End If
Catch ex As Exception
End Try
End Sub

So any help or redirection to make the authentication from the database
not
from the App_Data will be appreciated.

Regard's

Husam

May 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2406
by: NohaKhalifa | last post by:
Dear All; I'm developing a web site and i need to make adminisration for this site it's a site for Real Estates . But I don't need the administration to be online .. I want them to fill data...
4
5166
by: xixi | last post by:
i have a very serious memory problem, we have db2 udb v8.1 load on a HP titanium machine with 4 G memory, it is 64bit machine, currently on DB2 instance , i have three databases, but only one is...
5
4202
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
2
5311
by: Tony O'Bryan | last post by:
I am normally the admin for our PostgreSQL servers, but someone else tried to kill a runaway query while I was out sick. Unfortunately, he tried killing the runaway query by killing the...
22
4289
by: b_r | last post by:
Hi, I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL Server. The code is as follows: Dim sConnectionString As String = _ "Data...
3
1402
by: dani kotlar | last post by:
I use a table adapter to add rows to a database, using Update(); After adding a row to the database and closing the application, if I run the application again, and call Fill(), I can see the new...
0
927
by: srinivaspnv21 | last post by:
retriveing image in datalist or gridview controls from sql server 2000 in asp.net as well as inserting a image. plz help, thanks in advance
4
1953
by: cwilliams01 | last post by:
Hello I am new to VB.NET, so sorry if this is really obvious. I have written the following code to fill my dataset from a stored procedure requiring 1 paramter input (from a SQL database). The...
0
950
by: Sameera | last post by:
Hi, Could any one help me out on how to retriveing the supported formats for the installed Word version in C#. Thanks
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.