Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys, i have a problem in my log in page.

this is my code.

VB
Imports System
Imports System.Collections.Generic
'Imports System.Ling
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = ""
        'SqlDataSource1.ConnectionString = "Data Source=ML0002298641\SQLEXPRESS;Initial Catalog=dbFluor;Integrated Security=True"

        If Not Me.IsPostBack Then
            ViewState("LoginErrors") = 0
        End If
    End Sub

    'Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
    '    If YourValidationFunction(Login1.UserName, Login1.Password) Then
    ' e.Authenticated = true;
    '        Login1.Visible = False
    '        Label1.Text = "Successfully Logged In"
    '    Else
    '        e.Authenticated = False
    '    End If
    'End Sub

    Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As EventArgs)
        If ViewState("LoginErrors") Is Nothing Then
            ViewState("LoginErrors") = 0
        End If
        Dim ErrorCount As Integer = CInt(ViewState("LoginErrors")) + 1
        ViewState("LoginErrors") = ErrorCount
        If (ErrorCount > 3) AndAlso (Login1.PasswordRecoveryUrl <> String.Empty) Then
            Response.Redirect(Login1.PasswordRecoveryUrl)
        End If
    End Sub

    Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean
        Dim boolReturnValue As Boolean = False
        Dim strConnection As String = "Data Source=10.16.67.73;Initial Catalog=TestSQL;Integrated Security=True" '"server=.;Database=Database;uid=sa;pwd=wintellect;"
        'Dim strConnection As String = "Server=.\SQLExpress;DataBase=TestSQL;Integrated Security=SSPI"
        Dim sqlConnection As New SqlConnection(strConnection)
        'Dim SQLQuery As String = "SELECT LogName, LogPass FROM tblLog"
        Dim SQLQuery As String = "SELECT     LogMe.*, User_ID AS Expr1, Name AS Expr2, Cost_Center AS Expr3, Role_ID AS Expr4, Password AS Expr5 LogName = '" & Login1.UserName & "' AND LogPass = '" & Login1.Password & "' "

        Dim command As New SqlCommand(SQLQuery, sqlConnection)
        Dim Dr As SqlDataReader

        sqlConnection.Open()

        Dr = command.ExecuteReader()

        While Dr.Read()

            If (UserName = Dr("LogName").ToString()) And (Password = Dr("LogPass").ToString()) Then
                boolReturnValue = True
            End If

            Dr.Close()
            Return boolReturnValue
        End While
        Return boolReturnValue
    End Function


    Protected Sub Login1_Authenticate1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        If YourValidationFunction(Login1.UserName, Login1.Password) Then
            ' e.Authenticated = true;
            Login1.Visible = False
            Label1.Text = "Successfully Logged In"

        Else
            e.Authenticated = False
        End If
    End Sub
End Class


and i have getting a problem in this line.

VB
Dr = command.ExecuteReader()

       While Dr.Read()

           If (UserName = Dr("LogName").ToString()) And (Password = Dr("LogPass").ToString()) Then
               boolReturnValue = True
           End If

           Dr.Close()
           Return boolReturnValue
       End While


i hope you can help me.
thank you
Posted
Updated 2-May-11 15:15pm
v2
Comments
thatraja 2-May-11 21:15pm    
what's the error message? update that in your question.
chaosgray 2-May-11 21:21pm    
incorrect syntax.

try this

VB
If (UserName == Dr("LogName").ToString()) And (Password == Dr("LogPass").ToString()) Then
 
Share this answer
 
Comments
chaosgray 2-May-11 22:44pm    
there is still an error
try Putting Dr.Close() outsite the while loop
 
Share this answer
 

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