You could try locking the user/passwd table with SQL:
"LOCK TABLES users WRITE"
If you need to lock more tables, just list them in a comma-sepparated list at the end: "... users WRITE, foo WRITE, bar WRITE, ..."
If the table is locked like this, only the user with the lock can read or write to it. Of course, if it is already locked, then you'll have to wait until it unlocks, so you should setup a timeout to unlock it, if the user isn't active, and when they log out: "UNLOCK TABLES" is the SQL.
Does that help?