Solved

Login - Username and Password

Posted on 2006-07-15
39
4,315 Views
Last Modified: 2008-02-01
Ok, this is a similiar sample that I posted earlier, Login. It keeps saying the password is invalid. Username is not changed. It does not redirect to a "default.aspx". I checked Query Analyzer and verified username and password.



Imports System.Data.SqlClient

Partial Class Login
    Inherits System.Web.UI.Page

 
 

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

        Dim Authen As Boolean = False
        Authen = MyCustAuthen(Login1.UserName, Login1.Password)
        e.Authenticated = Authen
        If Authen = True Then
            Response.Redirect("default.aspx")

        End If
    End Sub
    Private Function MyCustAuthen(ByVal UserName As String, ByVal Password As String) As Boolean

       

        Dim BoolReturnValue As Boolean = False
        Dim StrCon As String = "Data Source=mcci\superman;Initial Catalog=Login;Persist Security Info=True;User ID=myusername;Password=mypassword"
        Dim Con As SqlConnection = New SqlConnection(StrCon)
        Dim Strselect As String = "select * from Loginnow"
        Dim myCommand As SqlCommand = New SqlCommand(Strselect, Con)
        Dim Dr As SqlDataReader


        Try

            Con.Open()

            Dr = myCommand.ExecuteReader


            While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                End If
                Dr.Close()

                Return BoolReturnValue


            End While



        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try
       

    End Function


End Class
0
Comment
Question by:VBdotnet2005
  • 24
  • 15
39 Comments
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17114608
what is wrong here?

do you want to redirect to default.aspx, and this code didn't do that?
0
 

Author Comment

by:VBdotnet2005
ID: 17114653
No. It did not redirect to default.aspx. It keeps saying the login is invalid. The textbox"Username" it did not clear out. It stays to the value whatever I input, lets say, Jack and it password is the only one I have to enter.
0
 

Author Comment

by:VBdotnet2005
ID: 17114657
Ok here is the username : Jack and the password is : SParrow
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17114666
so you want to do this:
after the user login incorrectly, the login control, keep the user name and clear the password textbox, so the user can input only the password?


0
 

Author Comment

by:VBdotnet2005
ID: 17114676
Exectly, that's what it does. I can't tell wheter the username or the password is incorrect.
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17114845
did you use failurText property of Login1
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17114860
or you can convert the login control to webtemplate, so you have access to all controls on it, and also access to failur label, and you can set it visible and invisible

0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17114885
I set the failur text, and then in  Login1_Authenticate set

e.Authenticated = false;

so the login control show the failur text,

if you use it, what is wrong?
0
 

Author Comment

by:VBdotnet2005
ID: 17116339
This line


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


"name" and "passwordx"  are supposed to be the same as Column Name in Enterprise Manager, right?
0
 

Author Comment

by:VBdotnet2005
ID: 17116355
I set a break point here

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

received this error

error -       System.IndexOutOfRangeException      {"Password"}      System.IndexOutOfRangeException
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116548
do you write correct field name?

passwordx or password?

check it by your table in enterprise manager, character by character.
0
 

Author Comment

by:VBdotnet2005
ID: 17116551
What does it means?

Item = In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
0
 

Author Comment

by:VBdotnet2005
ID: 17116568
in Enterprise manager, I put this

Column name

passwordx  

data type

Char

lenght

10

Allow Nulls is checked
0
 

Author Comment

by:VBdotnet2005
ID: 17116573
Loginnow Table I have 3 columns

Id - set as primary key , increment by 1
name
passwordx
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116575
ok,

let use int indexes instead of string indexes: so you want to change

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

to

If (UserName = Dr(1).ToString And Password = Dr(2).ToString) Then
0
 

Author Comment

by:VBdotnet2005
ID: 17116588

I have tried that, but it does not work.

If (UserName = Dr(1).ToString And Password = Dr(2).ToString) Then


...


I set a break point here

If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
or your code


If (UserName = Dr(1).ToString And Password = Dr(2).ToString) Then


under Autos   +++

Dr(1) ---- value is "John"  type Object   ---------------John is the first name in Loginnow, this is definately wrong
string is "John"  

Password is "sparrow"
Username is "Jack"




0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116594
if you have a table like this:

col1, col2, col3, col4, col5

and you want to use 4th column of your table should use Dr(3),

so if the username filed in your table is 3th field change the Dr(1) to Dr(2),

indexes strat from 0.
0
 

Author Comment

by:VBdotnet2005
ID: 17116595
Of course, this is what I used.

Jack Sparrow is #6 in Query Analyzer

Password is "sparrow"
Username is "Jack"
0
 

Author Comment

by:VBdotnet2005
ID: 17116596
I do understand is part.

"so if the username filed in your table is 3th field change the Dr(1) to Dr(2),

indexes strat from 0."
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116604
what's wrong now?
0
 

Author Comment

by:VBdotnet2005
ID: 17116605
What you think about this one?

Dr(1) ---- value is "John"  type Object   ---------------John is the first name (ID #1) in Loginnow, this is definately wrong
string is "John"  

This is what I just typed in.

Password is "sparrow"
Username is "Jack"
0
 

Author Comment

by:VBdotnet2005
ID: 17116611

It labled this

Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116617
i find the bug:

when u use this sql command

Dim Strselect As String = "select * from Loginnow"

then it return all information in Loginnow table, and beacuase you check only one of return values, can't find the username you enter,

so you have to way to correct that:

1: change the sql command string like this:

Dim Strselect As String = "select * from Loginnow where name='" & UserName &"' and passwords='" & Password & "' "


2:
change th while loop to check all values returned:

While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                End If
End While

Dr.Close()

Return BoolReturnValue
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116619
use failure action property
0
 

Author Comment

by:VBdotnet2005
ID: 17116638

Dim Strselect As String = "select * from Loginnow where name='" & UserName &"' and passwords='" & Password & "' "

supposed to be

Dim Strselect As String = "select * from Loginnow where name='" & UserName &"' and passwordx='" & Password & "' "

this is changed

While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                End If
End While

...

still


Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116642
Ooooooops also change this:

            While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                    Dr.Close()
                    Return BoolReturnValue
                End If
            End While
            Dr.Close()
            Return BoolReturnValue

0
 

Author Comment

by:VBdotnet2005
ID: 17116651
The entire code

-------------------


Imports System.Data.SqlClient

Partial Class Login
    Inherits System.Web.UI.Page

 
 

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

        Dim Authen As Boolean = False
        Authen = MyCustAuthen(Login1.UserName, Login1.Password)
        e.Authenticated = False
        If Authen = True Then
            Response.Redirect("default.aspx")

        End If
    End Sub
    Private Function MyCustAuthen(ByVal UserName As String, ByVal Password As String) As Boolean

       

        Dim BoolReturnValue As Boolean = False
        Dim StrCon As String = "Data Source=MCCI\superman;Initial Catalog=Login;Persist Security Info=True;User ID=myusernamePassword=password"
        Dim Con As SqlConnection = New SqlConnection(StrCon)

        Dim Strselect As String = "select * from Loginnow where name='" & UserName & "' and passwordx='" & Password & "' "
        Dim myCommand As SqlCommand = New SqlCommand(Strselect, Con)
        Dim Dr As SqlDataReader


        Try

            Con.Open()

            Dr = myCommand.ExecuteReader

           
            While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                End If
                Dr.Close()

                Return BoolReturnValue


            End While




        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try
       

    End Function


End Class
0
 

Author Comment

by:VBdotnet2005
ID: 17116657
still does not work  -   I am about to give up


Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"
0
 

Author Comment

by:VBdotnet2005
ID: 17116662


Anything else you can think of. I will continue it tomorrow. I'm off to bed now. Thank you for your help.
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17116663
when you set this:

e.Authenticated = False

then you want that code works properly,
you should change it to:

e.Authenticated = Authen
0
 

Author Comment

by:VBdotnet2005
ID: 17116669
The entire code  - still

Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"

Tomorrow, I will create a brand new table and a brand new asp.net project and see if that help(with the same code)

-------------------


Imports System.Data.SqlClient

Partial Class Login
    Inherits System.Web.UI.Page

 
 

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

        Dim Authen As Boolean = False
        Authen = MyCustAuthen(Login1.UserName, Login1.Password)
        e.Authenticated = Authen
        If Authen = True Then
            Response.Redirect("default.aspx")

        End If
    End Sub
    Private Function MyCustAuthen(ByVal UserName As String, ByVal Password As String) As Boolean

       

        Dim BoolReturnValue As Boolean = False
        Dim StrCon As String = "Data Source=MCCI\superman;Initial Catalog=Login;Persist Security Info=True;User ID=myusernamePassword=password"
        Dim Con As SqlConnection = New SqlConnection(StrCon)

        Dim Strselect As String = "select * from Loginnow where name='" & UserName & "' and passwordx='" & Password & "' "
        Dim myCommand As SqlCommand = New SqlCommand(Strselect, Con)
        Dim Dr As SqlDataReader


        Try

            Con.Open()

            Dr = myCommand.ExecuteReader

           
            While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                End If
                Dr.Close()

                Return BoolReturnValue


            End While




        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try
       

    End Function


End Class
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17117361
check with this:

Imports System.Data.SqlClient

Partial Class Login
    Inherits System.Web.UI.Page

 
 

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

        Dim Authen As Boolean = False
        Authen = MyCustAuthen(Login1.UserName, Login1.Password)
        e.Authenticated = Authen
        If Authen = True Then
            Response.Redirect("default.aspx")

        End If
    End Sub
    Private Function MyCustAuthen(ByVal UserName As String, ByVal Password As String) As Boolean

       

        Dim BoolReturnValue As Boolean = False
        Dim StrCon As String = "Data Source=MCCI\superman;Initial Catalog=Login;Persist Security Info=True;User ID=myusername;Password=password"
        Dim Con As SqlConnection = New SqlConnection(StrCon)

        Dim Strselect As String = "select * from Loginnow where name='" & UserName & "' and passwordx='" & Password & "' "
        Dim myCommand As SqlCommand = New SqlCommand(Strselect, Con)
        Dim Dr As SqlDataReader


        Try

            Con.Open()

            Dr = myCommand.ExecuteReader

           
            While Dr.Read
                If (UserName = Dr("name").ToString And Password = Dr("passwordx").ToString) Then
                    BoolReturnValue = True
                    Dr.Close()
                    Return BoolReturnValue
                End If
            End While

            Dr.Close()

            Return BoolReturnValue




        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try
       

    End Function


End Class
0
 

Author Comment

by:VBdotnet2005
ID: 17117468
Did you changed anything? I can't tell.
0
 

Author Comment

by:VBdotnet2005
ID: 17117472
I tried to creat a new table, but still give me the same result. There shouldn't be any errors there, right?

Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"
0
 

Author Comment

by:VBdotnet2005
ID: 17117478
How about Login1 properties? Should I change anything there?
0
 

Author Comment

by:VBdotnet2005
ID: 17117505
oK. I created a brand new database name "Loginonweb" and table name is "Logmein" so we will get confused with Name and password or passwordx
It still gives me the same result

Your login attempt was not successful. Please try again.

It does not redirect to "default.aspx"




cloumn name   data type   lenght allow nulls
id                     int            4         unchecked
cid                   char          10       checked
zipcode            numeric     9         checked




Imports System.Data.SqlClient

Partial Class Login
    Inherits System.Web.UI.Page

 
 

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

        Dim Authen As Boolean = False
        Authen = MyCustAuthen(Login1.UserName, Login1.Password)
        e.Authenticated = Authen
        If Authen = True Then
            Response.Redirect("default.aspx")

        End If
    End Sub
    Private Function MyCustAuthen(ByVal UserName As String, ByVal Password As String) As Boolean

       

        Dim BoolReturnValue As Boolean = False
        Dim StrCon As String = "Data Source=MCCI\superman;Initial Catalog=Loginonweb;Persist Security Info=True;User ID=ashley;Password=password"
        Dim Con As SqlConnection = New SqlConnection(StrCon)

        Dim Strselect As String = "select *from Logmein where cid = '" & UserName & "' and zipcode ='" & Password & "' "
        Dim myCommand As SqlCommand = New SqlCommand(Strselect, Con)
        Dim Dr As SqlDataReader


        Try

            Con.Open()

            Dr = myCommand.ExecuteReader

           
            While Dr.Read
                If (UserName = Dr("cid").ToString And Password = Dr("zipcode").ToString) Then
                    BoolReturnValue = True
                    Dr.Close()
                    Return BoolReturnValue
                End If
            End While
            Dr.Close()
            Return BoolReturnValue




        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try
       

    End Function


End Class
0
 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
ID: 17117523
did you check the MyCustAuthen line by line, and check why with the correct username and password, it returns false?
0
 

Author Comment

by:VBdotnet2005
ID: 17117567
Yes, I did. Username = Z16 and password = 93232 and that is what I have on the table. They matched,but it still returns false, which I just don't get it.
0
 

Author Comment

by:VBdotnet2005
ID: 17122520

Have you thought of anything else?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now