INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Log-in form question

Log-in form question

(OP)
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 www.mysite.com site? This is the Login.aspx.vb script that I have at the moment:

CODE --> vb.net

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

RE: Log-in form question

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.

RE: Log-in form question

(OP)
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!

RE: Log-in form question

(OP)
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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close