Important: Please read the Qt Code of Conduct -

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

  • 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! :)

  • 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 :)

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

  • 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:
    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.

Log in to reply