I have the following stored procedure to authenticate users on my website:
This authenticates against the babysitters table. However, I have parents who can login as well and their details are stored in a different table. Can i authenticate against two tables. So it checks the first table, then the second.
This is my code for the login button:
Code:
USE [keystrategy]
GO
/****** Object: StoredProcedure [dbo].[DBAuthenticate] Script Date: 03/01/2012 11:46:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DBAuthenticate]
(
@Username nvarchar(50),
@Password nvarchar (10)
)
AS
DECLARE @ID INT
DECLARE @ActualPassword nvarchar(10)
SELECT
@ID = IdentityCol,
@ActualPassword = Password
FROM dbo.Babysitters
WHERE EmailAddress = @Username
IF @ID IS NOT NULL
IF @Password = @ActualPassword
RETURN @ID
ELSE
RETURN - 2
ELSE
RETURN - 1
This authenticates against the babysitters table. However, I have parents who can login as well and their details are stored in a different table. Can i authenticate against two tables. So it checks the first table, then the second.
This is my code for the login button:
Code:
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If IsValid Then
If DBAuthenticate(txtUsername.Text, txtPassword.Text) > 0 Then
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)
Session("User") = txtUsername.Text
Response.Redirect("secure/home.aspx")
End If
End If
End Sub
Function DBAuthenticate(ByVal strUsername As String, ByVal strPassword As String) As Integer
Dim conUsers As SqlConnection
Dim strConnection As String
Dim cmdSelect As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Integer
strConnection = ConfigurationManager.ConnectionStrings("KeyStrategyConnectionString").ConnectionString
conUsers = New SqlConnection(strConnection)
cmdSelect = New SqlCommand("DBAuthenticate", conUsers)
cmdSelect.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
parmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSelect.Parameters.AddWithValue("@username", strUsername)
cmdSelect.Parameters.AddWithValue("@password", strPassword)
conUsers.Open()
cmdSelect.ExecuteNonQuery()
intResult = cmdSelect.Parameters("RETURN_VALUE").Value
conUsers.Close()
If intResult < 0 Then
If intResult = -1 Then
lblMessage.Text = "Username not found!"
Else
lblMessage.Text = "Invalid Password!"
End If
End If
Return intResult
End Function