Prevent multiple logins from the same USER ID (user only could login once)

hai there …

if we want to protect login, how it could be?

for example user “A” login in computer A

and then another user couldn’t login as “A” in another computer

do you have an idea about this?

you need to add code on login to check the session table and error out if there the same user id.

Mmmh damn I built some lines for this problems some months ago but didn’t find them :frowning:

Put some code in the OnOpen Trigger of your Main Menu which throws an Error if it find more then one Session Record for the current USERID . I also added a check for a special role with which the User is allowed to have multiple sessions. But this doesn’t prevend on multiple sessions via C/Front and ODBC!

Instead of the Main Menu you can also try some examples with Codeunit 1, maybe this will also prevend ODBC and C/Front Login??

on what form?

or in table?

You don’t have a main menu form from 4.0 SP1 onwards. So you would have to use Codeunit 1. Add it into Login Start Function.

something like

Session.Reset;
Session.Setrange(“My session”,False);
Session.Setrange(“User ID”,userid);
If Not(Session.isempty) then
Error(…);

Where Session is a global/Local of Type Record Session

I strongly advise you to export Codeunit 1 before making the changes so you have a backup, and test on a test server.

This is purely untested and I just have not written the code for real so you will have to try it.

/TH

Session.Reset;
Session.Setrange(“My session”,False);
Session.Setrange(“User ID”,userid);
If Not(Session.isempty) then
Error(…);

—> session?

what data type it should be then?

sorry, newbie :stuck_out_tongue:

Session it s global of type “Record” in the subtype you need to type “Session” its a system table so you cannot modify it

/TH

Hai Tony, your code is really well done for me :slight_smile:

that’s what i want to , hehe…

but it still could log in, and coukld show the error message i made

i add a code EXIT ;

but it still login… do you have any idea?

Session.RESET;
Session.SETRANGE(“My Session”,FALSE);
Session.SETRANGE(“User ID”,USERID);
IF NOT(Session.ISEMPTY) THEN
ERROR(Text999);
exit;

another question

while browse using F5, i found Session.“Idle Time” :=1;

what is it used for?

Hey Stan,

Where did you add the code? Which trigger.

The idle time in the session table is the time since that user did anything in Navision, Its maintained by the DBMS.

/TH

Hey Stan,

I just tried this on one of my Databases. Using the CompanyOpen trigger and it gave me an error and would not let me continue.

I also just whacked into the LogInStart as the first code that is executed and that also caused the error.

/TH

LogInStart()

Language.SETRANGE(“STX File Exist”,TRUE);
Language.SETRANGE(“Globally Enabled”,TRUE);
Language.“Language ID” := GLOBALLANGUAGE;
IF NOT Language.FIND THEN BEGIN
Language.“Language ID” := WINDOWSLANGUAGE;
IF NOT Language.FIND THEN
Language.“Language ID” := ApplicationLanguage;
END;
GLOBALLANGUAGE := Language.“Language ID”;

IF NOT GLSetup.GET THEN BEGIN
CompanyInitialize.RUN;
COMMIT;
CLEAR(CompanyInitialize);
END;

IF CompanyNotesSetup.GET THEN
IF CompanyNotesSetup.“Company Notes Path” <> ‘’ THEN
StartCompanyNotes.RUN;

LogInDate := TODAY;
LogInTime := TIME;
LogInWorkDate := 0D;
IF STRPOS(COMPANYNAME,Text000) = 1 THEN
IF GLEntry.READPERMISSION THEN BEGIN
GLEntry.SETCURRENTKEY(“G/L Account No.”,“Posting Date”);
OK := TRUE;
REPEAT
GLEntry.SETFILTER(“G/L Account No.”,’>%1’,GLEntry.“G/L Account No.”);
GLEntry.SETFILTER(“Posting Date”,’>%1’,GLEntry.“Posting Date”);
IF GLEntry.FIND(’-’) THEN BEGIN
GLEntry.SETRANGE(“G/L Account No.”,GLEntry.“G/L Account No.”);
GLEntry.SETRANGE(“Posting Date”);
GLEntry.FIND(’+’);
END ELSE
OK := FALSE
UNTIL NOT OK;
IF NOT (GLEntry.“Posting Date” IN [0D,WORKDATE]) THEN BEGIN
MESSAGE(
Text001 +
Text002 +
Text003,
COMPANYNAME,NORMALDATE(GLEntry.“Posting Date”));
LogInWorkDate := WORKDATE;
WORKDATE := NORMALDATE(GLEntry.“Posting Date”);
END;
END;

RMSetup.GET;
IF (RMSetup.“E-Mail Logging User ID” <> ‘’) AND (RMSetup.“E-Mail Logging User ID” = UPPERCASE(USERID)) THEN
CODEUNIT.RUN(CODEUNIT::“E-Mail Dispatcher”);

IF (USERID <> ‘’) AND (Salesperson.READPERMISSION) THEN BEGIN
Salesperson.SETRANGE(“Navision User ID”,USERID);
Salesperson.SETRANGE(“Enable Synchronization”,TRUE);
IF Salesperson.FIND(’-’) THEN
StartOutlookSyncronization;
END;

Session.RESET;
Session.SETRANGE(“My Session”,FALSE);
Session.SETRANGE(“User ID”,USERID);
IF NOT(Session.ISEMPTY) THEN
BEGIN
message(Text999);
END;

→ code unit 1 , function login start

it still could log in

Hey Stan,

Okay, move it to run before any other code. If that fails add it to the CompanyOpen trigger, use Error not Message.

Also, and this is personal preference but how Navision do it. But I normally put the “begin” and “End” Expressions as in the statement currently above yours. I find it easier to read.

but its personally preference.

/TH

CompanyOpen()
Session.RESET;
Session.SETRANGE(“My Session”,FALSE);
Session.SETRANGE(“User ID”,USERID);
IF NOT(Session.ISEMPTY) THEN
BEGIN
error(Text999);
END;

IF GUIALLOWED THEN
LogInStart;

→ do you mean like this? i already tried it… but it was the same

Are you running SQL or Native? should be working fine.

You are logging into the same database once, then logging into another?

i use sql database

i login as stan in database “A”

and then i login as stan once more in database “A”

or could send to my email codeunit 1 ?

thanx

I was developing this in 3.7. Just moved to 4.0 Sp3 SQL with Windows Auth and am having the same issues.

Let me look into it some more and I’ll get back to you.

I know one of the issues is the Windows Auth. When I call UserID its stripped off the domain.

/TH

it’s ok then

my company didn’t use windows auth since the first time

thanx for your help

Hey Stan,

Upon in investigation I don’t think this is possible with the MenuSuite. I can get the error to call under the right conditions, but cannot see the hook to the MenuSuite Load function.

Maybe someone on here does, but at the moment I just can’t see how to stop it.

With the old Form 330 the error would override the Form.Run call.

I don’t think this is going to be possible.

Sorry you wasted time looking at it.

/TH

hmmmmmm it’s okay then…

thank you very much for your effort for helping me Tony

does anybody could help me?

btw… Form 330 → i don’t have it

Nobody has form 330 in 4.0.

Form 330 was the main menu-form in older versions. Menusuites are new in version 4.0.