Login problem

asp.net , db Albania
  • 13 years ago

    Hello, I'm writing an aspx form and need to check the login so if the user exist he can upload file if doesn't then he must register, I'm using the login control in visual studio but it's not working. I use this code:

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate

    Dim Authenticated As Boolean = False

    Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password)

    e.Authenticated = Authenticated

    If Authenticated = True Then

    Response.Redirect("login_true.aspx")

    End If

    End Sub

    Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean

    Dim boolReturnValue As Boolean = False

    'Dim strConnection As String = "datasource"

    Dim Connection As SqlConnection = New SqlConnection(conn)

    Dim strSQL As String = "Select * From Table1"

    Dim command As SqlCommand = New SqlCommand(strSQL, Connection)Dim Dr As SqlDataReader

    Connection.Open()

    Dr = command.ExecuteReader

    While Dr.Read

    If ((UserName = Dr("UserName").ToString) And (Password = Dr("Pass").ToString)) Then

    boolReturnValue = True

    End If

    Dr.Close()

    Return boolReturnValue

    End While

    End Function

     

    I get this code from the internet but it doesn't work for me, any ideas

  • 13 years ago

    Hi there,

    The Method

        Public Function ValidateUser(ByVal username As String, ByVal password As String) As Boolean
    Dim retval As Integer

    Dim sqldb As New SqlDataProvider.SqlDatabase("ConnectionString")
    sqldb.ExecuteNonQuery("dbo.ValidateUser", retval, username, password)

    Return retval
    End Function

    The Stored Procedure

    Create Procedure dbo.ValidateUser
    (
    @Username nvarchar(256),
    @Password nvarchar(128)
    )
    As
    Begin
    If Exists(Select * From dbo.Users Where (Username = @Username) And (Password = @Password))
    Return 1
    End

    You can use SQLDataProvider Class

    Hope this helps

  • 13 years ago

    Try this... 

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate

    Dim Authenticated As Boolean = False

    Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password)

    e.Authenticated = Authenticated

    If Authenticated = True Then

    Response.Redirect("apage.aspx")

    End If

    End Sub

    Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean

    Dim boolReturnValue As Boolean = False

    'Dim strConnection As String = "datasource"

    Dim Connection As SqlConnection = New SqlConnection(your server creds)

    Dim strSQL As String = "Select * From tbllogin WHERE LoginName = '" & Login1.UserName & "'"

    Dim command As SqlCommand = New SqlCommand(strSQL, Connection)Dim Dr As SqlDataReader

    Connection.Open()

    Dr = Command.ExecuteReader

    While Dr.Read

    If ((UserName = Dr("LoginName").ToString) And (Password = Dr("PassWord").ToString)) Then

    boolReturnValue = True

    End If

    Dr.Close()

    Return boolReturnValueEnd While

     

     

    End Function

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou