How to prevent simultaneous login with same user on different pcs
USING SP FOR AUTHENTICATE ,SESSION LOG OUT
How to prevent simultaneous login with same user on different pcs
USING SP FOR AUTHENTICATE ,SESSION LOG OUT
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Apr 18, 2023, 3:31 AM EDT
Create a session table in your database that stores the user ID, session ID, and login time. When a user logs in, generate a unique session ID and store it in the session table along with the user ID and login time. Create a stored procedure that checks the session table for the existence of a session ID associated with the user ID. If the stored procedure finds a session ID, it can either log out the user from the previous session or prevent the new login attempt. When the user logs out, delete the session ID from the session table.
Here is a sample code for the stored procedure:
CREATE PROCEDURE CheckSession @UserID int, @SessionID varchar(50) AS BEGIN SET NOCOUNT ON; -- Check if the user has an active session IF EXISTS(SELECT * FROM SessionTable WHERE UserID = @UserID AND SessionID <> @SessionID) BEGIN -- Log out the user from the previous session UPDATE SessionTable SET LogoutTime = GETDATE() WHERE UserID = @UserID AND SessionID <> @SessionID END ELSE BEGIN -- Insert a new session record INSERT INTO SessionTable (UserID, SessionID, LoginTime) VALUES (@UserID, @SessionID, GETDATE()) END ENDYou can call this stored procedure when the user logs in and pass the user ID and session ID as parameters. The stored procedure will check if the user has an active session and log them out from the previous session if necessary. If the user doesn't have an active session, the stored procedure will insert a new session record.
To log out the user, you can either redirect them to a logout page or simply delete the session record from the session table. Here is a sample code to delete the session record:
DELETE FROM SessionTable WHERE UserID = @UserID AND SessionID = @SessionIDYou can call this code when the user logs out or when their session expires.
Sandeep KumarRank #1,642 · 937 reputationPosted Apr 19, 2023, 3:06 AM EDT
is this sp for user authenticate, then where password parameter