Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Prevent Multiple Same User Logins On A Desktop Application C#

Prevent Multiple Same User Logins On A Desktop Application C#

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadmin
6 Posts 2 Posters 0 Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    Zeyad Jalil
    wrote on last edited by
    #1

    Hi All, I have a windows form application (C#) and the users can login to the application by user name and password, and I need to prevent the same user to login to the system from different machines or only one time login, and if the user is logged in I need to disallow a login with a notification the user is already logged in. C# Desktop Application Not Web With MS SQL Server Database Thank you

    W 1 Reply Last reply
    0
    • Z Zeyad Jalil

      Hi All, I have a windows form application (C#) and the users can login to the application by user name and password, and I need to prevent the same user to login to the system from different machines or only one time login, and if the user is logged in I need to disallow a login with a notification the user is already logged in. C# Desktop Application Not Web With MS SQL Server Database Thank you

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      One way to do this is to query if there already is a session for that specific user in the system. You can get the information from sys.dm_exec_sessions[^] Since not every user is allowed to query that view, it's best if you do the check inside a stored procedure upon connecting to the database. If the connection is already found (or actually if there now is two connections) then raise an error from the procedure to inform client application that new connection isn't allowed. Another option is to use Logon Triggers[^] Depending on the requirements, you can check if the host is different if you need to allow multiple connections from the same host

      Z 1 Reply Last reply
      0
      • W Wendelius

        One way to do this is to query if there already is a session for that specific user in the system. You can get the information from sys.dm_exec_sessions[^] Since not every user is allowed to query that view, it's best if you do the check inside a stored procedure upon connecting to the database. If the connection is already found (or actually if there now is two connections) then raise an error from the procedure to inform client application that new connection isn't allowed. Another option is to use Logon Triggers[^] Depending on the requirements, you can check if the host is different if you need to allow multiple connections from the same host

        Z Offline
        Z Offline
        Zeyad Jalil
        wrote on last edited by
        #3

        Hi, dm_exec_sessions is about sql user authentication, but I need for my application users In my application database I have a users table with login name and Password I need to check if the User is open the application and logged in I want prevent it login again from the same PC or from different PC's Thanks

        W 2 Replies Last reply
        0
        • Z Zeyad Jalil

          Hi, dm_exec_sessions is about sql user authentication, but I need for my application users In my application database I have a users table with login name and Password I need to check if the User is open the application and logged in I want prevent it login again from the same PC or from different PC's Thanks

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          First of all, dm_exec_sessions contains rows for both SQL Server authenticated users and Windows authenticated users. So regardless of the authentication method, a row exists if a connection exists. What comes to user identification, do you have information about the actual OS user in your user table? If you do, you could use that info from nt_user_name column and check if that user matches.

          W 1 Reply Last reply
          0
          • W Wendelius

            First of all, dm_exec_sessions contains rows for both SQL Server authenticated users and Windows authenticated users. So regardless of the authentication method, a row exists if a connection exists. What comes to user identification, do you have information about the actual OS user in your user table? If you do, you could use that info from nt_user_name column and check if that user matches.

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Sorry coming back so late, but if you still have open questions concerning this, have a look at Restricting logon to SQL Server[^]. Perhaps there would be some usable ideas for you.

            1 Reply Last reply
            0
            • Z Zeyad Jalil

              Hi, dm_exec_sessions is about sql user authentication, but I need for my application users In my application database I have a users table with login name and Password I need to check if the User is open the application and logged in I want prevent it login again from the same PC or from different PC's Thanks

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              Sorry for coming back so late, but if you still have open questions concerning this, have a look at Restricting logon to SQL Server[^] . Perhaps there would be some usable ideas for you.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups