User licensing control

I have a remote Postgres database with a desktop app where I want some of my users to be only allowed to log in on only one computer at a time.

My app is logging in and out of the database when needed so it really doesn’t help to set the number of users in Postgres to “1”.

I was thinking of keeping the connection alive, however, in case my app crashes, it takes a while for Postgres to release the user and the end-user can’t log in which makes the program unusable for a while.

What might be a good way to handle user licensing?

Can you get information about other users in Postgres? I have a similar situation in my app which I solved with the below code (Valentina):

dim theCursor as VCursor = theDatabaseConnection.SqlSelect("show connections")
if theCursor = Nil or theCursor.RecordCount = 0 then Return False

for currentConnection as Integer = 0 to theCursor.RecordCount
  theCursor.Position = currentConnection
  if theCursor.Field("fld_database").GetString = DatabaseName and theCursor.Field("fld_login").GetString <> Login then
    'we have already another user on the database
    Return True
  end if
Next

where “login” is the username.

This kind of stuff leads to security holes… it’s why most financial institutions don’t want to touch this kind of software. The best worst solution is to search the network for the existence another instance with the same unique footprint.

I’m not sure how to do this, but this sounds feasible - since most every circumstance would have another user on the same local network.

Re: Postgres users
I mentioned that since the database connection is only maintained for a short period of time to access the database, it wouldn’t be possible to find the existence of another user.