Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log-in form question

Status
Not open for further replies.

Blueie

Technical User
May 12, 2012
72
GB
Hello

In Visual Studio 2013 I have a small (two form) vb.net project. My 'new user' form inserts field form data in my MS Access database, and I have created a page that thanks the user for registering. The other form, Login.aspx is then supposed to log in this new user.

However, when I complete the log-in credentials correctly and press the 'OK' button, nothing happens: the username remains in its field and the password disappears. I don't get any errors when debugging, or 'Invalid username/password' after pressing 'OK'.

Ideally, the user who inputs log-in credentials correctly, should be sent to an external Classic ASP site which is already being hosted (I say external because I am only testing my ASP.NET project locally, and the external Classic site is not part of this project in Visual Studio at all). Is my log-in form static/doing nothing because I have not referenced that external site? This is the Login.aspx.vb script that I have at the moment:

Code:
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports Microsoft.Owin.Security

Partial Public Class Account_Login
    Inherits Page
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        RegisterHyperLink.NavigateUrl = "Register"
        OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")
        Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
        If Not [String].IsNullOrEmpty(returnUrl) Then
            RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & returnUrl
        End If
    End Sub

    '    Protected Sub LogIn(sender As Object, e As EventArgs)
    '        If IsValid Then
    '            ' Validate the user password
    '            Dim manager = New UserManager()
    '            Dim user As ApplicationUser = manager.Find(username.Text, password.Text)
    '            If user IsNot Nothing Then
    '                IdentityHelper.SignIn(manager, user, RememberMe.Checked)
    '                IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
    '            Else
    '                FailureText.Text = "Invalid username or password."
    '                ErrorMessage.Visible = True
    '            End If
    '        End If
    '    End Sub
    'End Class

    

Protected Sub LogIn(sender As Object, e As EventArgs) Handles btnLogin.Click

    If IsValid Then             ' Validate the user password             

        Dim manager = New UserManager()

        Dim user As ApplicationUser = manager.Find(username.Text, password.Text)

        Try

            If user IsNot Nothing Then

                IdentityHelper.SignIn(manager, user, RememberMe.Checked)

                IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)

            End If

        Catch ex As Exception

            FailureText.Text = ex.Message 'this should pump out the actual error line from the stack trace.

            ErrorMessage.Visible = True

        End Try

    End If

End Sub

End Class

There is no 'SELECT FROM......' or reference to my database path here, either, as there would be in Classic ASP.

What should I be adding to the above, please?

Thanks

Blueie
 
Hi Blueie,



Your statement "IsValid " I'm assuming is a type Boolean. I Don't see any handling for IsValis if its false.

Why don't you drop and else in there and try and trap for false.

If IsValid Then
do something

Else

do something

End IF

It may not be True which might explain why nothing is happening.
 
Hello Dashley

I am glad you have pointed that out. I have something like that already:

Code:
 If result > 0 Then
            Response.Redirect("upload.asp")
        Else
            FailureText.Text = "Invalid credentials"
        End If

I have just logged-in with incorrect credentials and the login form has remained where it is - onscreen - but I did not get the "Invalid credentials" message? On the other hand, debugging has not shown any errors. There is a default text under the log-in button: 'Register if you don't have a local account' but that doesn't really indicate "Invalid credentials".

If I purposely omit the username or password and press the 'Log On' button, there are default messages: 'The user name field is required' and 'The password field is required'.

Thanks for your message!

 
Hello Dashley

I see you have replied to an older question I have posted. This is the code I have now and it seems to work (it takes me to update.asp when I login correctly) apart from the "Invalid Credentials" I have mentioned in my post just now:

Code:
 Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim connect = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=|DataDirectory|students.mdb;"

        Dim query As String
        query = "Select Count(*) From university Where username = ? AND [password] = ?"
        Dim result As Integer = 0
        Using conn As New OleDbConnection(connect)
            Using cmd As New OleDbCommand(query, conn)
                cmd.Parameters.AddWithValue("", username.Text)
                cmd.Parameters.AddWithValue("", password.Text)
                conn.Open()
                Session("User") = username.Text
                result = DirectCast(cmd.ExecuteScalar(), Integer)
            End Using
        End Using
        If result > 0 Then
            Response.Redirect("upload.asp")
        Else
            FailureText.Text = "Invalid credentials"
        End If
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top