Command line login

This forum is for programmers who have questions about the source code.
Post Reply
ebussa
Posts: 2
Joined: Fri Mar 13, 2020 8:39 am

Command line login

Post by ebussa » Fri Mar 13, 2020 11:00 am

I am attempting to write a program that opens the Perio Chart form automatically. My program is very short:

Code: Select all

class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var odArgs = new string[] { "UserName=admin", "OdPassword=od123", "PatNum=11" };
            
            var start = new FormOpenDental(odArgs);
            start.Show();
            
            var perio = new FormPerio(new Patient() { PatNum = 11 }, null);
            perio.ShowDialog(start);
        }
    }
My problem is that the login screen is still appearing even though I'm passing in the UserName and OdPassword as command line arguments. This seems inconsistent but I'm guessing I am missing something in my configuration?

I have found in the source code where the ShowLogOn() dialog is being called but I'm not familiar with the configuration terms that are
being evaluated. Does anyone have know why the logon screen is still showing or have any suggestions as to what configuration will prevent it? Source code examples included below.

Thank you,
Ed.
________________________________________________________________________________________________

From the source code, I see that there are two different places where the program checks to see if there is a user logged in. One check returns false, the other one true. Both these checks are in the FormOpenDental.ProcessCommandLine() method:

RETURNS TRUE:

Code: Select all

				if(user==null) {
					//if(Programs.UsingEcwTight() && userName!="") {
					if(Programs.UsingEcwTightOrFullMode() && userName!="") {
						user=new Userod();
						user.UserName=userName;
						user.LoginDetails=Authentication.GenerateLoginDetailsMD5(passHash,true);
						//This can fail if duplicate username because of capitalization differences.
						Userods.Insert(user,new List<long> { PIn.Long(ProgramProperties.GetPropVal(ProgramName.eClinicalWorks,"DefaultUserGroup")) });
						DataValid.SetInvalid(InvalidType.Security);
					}
					else {//not using eCW in tight integration mode
						//So present logon screen
						ShowLogOn();
						user=Security.CurUser.Copy();
					}
				}
RETURNS FALSE:

Code: Select all

				if(passHash!=user.PasswordHash || !Programs.UsingEcwTightOrFullMode())//password not accepted or not using eCW
				{
					//So present logon screen
					ShowLogOn();
				}
				else {//password accepted and using eCW tight.
					//this part usually happens in the logon window
					Security.CurUser = user.Copy();
					SecurityLogs.MakeLogEntry(Permissions.UserLogOnOff,0,Lan.g(this,"User:")+" "+Security.CurUser.UserName+" "+Lan.g(this,"has logged on via command line."));
				}

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: Command line login

Post by cmcgehee » Mon Mar 16, 2020 7:56 am

Ed,

I believe you need to send the hash of the user's password instead of the actual password:

Code: Select all

var odArgs = new string[] { "UserName=admin", "PassHash=fjk3alvkajka3ljkfalja3kwg54898q32jha==", "PatNum=11" };
You can find the value of the hash by running this query in OD:

Code: Select all

SELECT Password FROM userod WHERE UserName='admin' 
Chris McGehee
Open Dental Software
http://www.opendental.com

ebussa
Posts: 2
Joined: Fri Mar 13, 2020 8:39 am

Re: Command line login

Post by ebussa » Mon Mar 16, 2020 8:32 am

Thanks for the tip Chris. Unfortunately, using the snippet you provided, the program still enters the manual logon dialog.

After keeping all of my parameters and adding the PassHash parameter as you suggested, it is now passing the first condition below, but fails on the second one (`!Programs.UsingEcwTightOrFullMode()`):

Code: Select all

	if(passHash!=user.PasswordHash || !Programs.UsingEcwTightOrFullMode())//password not accepted or not using eCW
	{
		//So present logon screen
		ShowLogOn();
	}

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: Command line login

Post by cmcgehee » Mon Mar 16, 2020 10:02 am

My apologies, I led you astray. The PassHash argument only works if you are using the eCW integration. If you want to be able to launch Open Dental without making the user log in, you could set up login based on the Windows user: https://opendental.com/manual/singlesignon.html
Chris McGehee
Open Dental Software
http://www.opendental.com

Post Reply