How to know which user is logged in?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kino
    New Member
    • Feb 2011
    • 19

    How to know which user is logged in?

    Hello,

    I have a Login page which checks if the user has entered the correct password by comparing it with values in the database.

    I have done this with two classes: one that gets the passwords from the sql database and another that compares this data with the data entered by the user.

    I have another page to which I redirect the users once they have successfully logged in (inside the Login button function). This new page is know as the User Profile page and I have to display a series of information regarding that particular user in this page.

    I can't figure out how to do this. Since the UserProfile is a new page, how will I know which user info needs to be displayed?

    Do I store the info and then display it in another page?

    Or is there a way to know the id of the user who has just logged in?

    I am new to ASP.NET and I'll be grateful if someone could help me with this.
    Last edited by Frinavale; Apr 27 '11, 02:33 PM. Reason: Formatted the question so that it is easier to read.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Typically, when someone logs in, the server sends a Token of some sort to the browser to indicate who the user is (and that they have successfully logged in).

    Once the browser has been issued this Token, ASP.NET will allow the user into "restricted " parts of the website.

    There are several ways to authenticate a user. The one that I was just describing is called Forms Authentication. It is the most common one used.

    Check out:

    A quick solution to your current implementation would be to set a Session Variable with some sort of information (like the User's ID) so that you can tell which user is logged in. (check out Session: how to pass information between webpages for information on how to use Session if you don't already know about this topic)

    -Frinny

    Comment

    • kino
      New Member
      • Feb 2011
      • 19

      #3
      Thank you so much, I'll read up on that.

      One more question. If I use sessions, will I then have to use that session info (username in this case) to retrieve the data again from the database, is that the best way to proceed?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Yes you would have to re-query the database...or you could store all of the user's information in Session so that you don't have to re-query the database.

        Comment

        • kino
          New Member
          • Feb 2011
          • 19

          #5
          Thanks a lot for your reply, I'll try doing that.

          Comment

          • Nicholas25
            New Member
            • Nov 2011
            • 9

            #6
            Or you can also use a data base using HTML or JavaScript together they allow you to get your user informationeg. login date ,last login ,password ,ETC

            -Nicholas
            If there are any enquiry this SHOULD be sent to my via-email at:<email removed>
            Last edited by Frinavale; Nov 10 '11, 02:48 PM. Reason: Email was removed. Please do not post your email address on this forum.

            Comment

            Working...