Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Session - Keeping track if user is logged in

[SOLVED] Session - Keeping track if user is logged in

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi,

    I have connected my Qt app with a mySQL database.
    I use a login form (custom QDialog) that check if the username and password are correct, if so, the main Window starts.

    This all work correctly, but I want to make sure only one user can connect at the same time with a corresponding user/password.

    I thought of adding a field in my DB called "isLoggedIn" and put this flag to 1 when the user login. The problem I have is to set this flag to 0 when the application is close. There is too many way that the application can clause (crash, user power off computer, ..) so the flag stays at 1 and the user can't login afterward

    Is there another way to do this that i'm missing? I could store a random ID field in a the mySQL user table, but the same problem happen, when did the user stop using the application? So I can let a new one update the id.

    Thanks in advance! :)


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      haa I got it I think

      When a new user login, update the sessionId.
      The one that was already loged will get kicked out, I have to verify sessionID all the time though

      Should think before posting :)


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        Out of curiosity, how did you connect the Qt app to the SQL database?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          At start I used QSqlDatabase and connect directly my client to the database. But I soon learned that this approach was not good since all my client will need a direct access to the DB (not secure...)

          So I made a web service using phprestsql, really easy to set up:
          http://phprestsql.sourceforge.net/
          Now when I need to make Select or an Update, I use the QNetworkRequest class and create appropriate "get, put, post and delete" request. So far only using basic http authentification, will need to get a ssl certificate so I can use https. Each request pass the username/password of the user to see if he has access to do what he's asking.


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved