Password Protect User C Programs

Moderators: TomKerekes, dynomotion

Post Reply
PBandJacob
Posts: 19
Joined: Thu Sep 02, 2021 6:02 pm

Password Protect User C Programs

Post by PBandJacob » Wed Jun 29, 2022 2:58 pm

Hello!
There is a file called KflopToKMotionCNCFunctions.c that contains a function called InputBox. It is as follows
#define GATH_OFF 0
int InputBox(char *s, float *value)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do
{
*p++ = *s++;
} while (s[-1]);
DoPCInt(PC_COMM_INPUT, GATH_OFF);
*value = *(float *)&persist.UserData[PC_COMM_PERSIST+2];
return persist.UserData[PC_COMM_PERSIST+3];
}

I've been using that function to bring up a dialog box and input a value. The two options in the box are "Cancel" and "Set". I am able to use this to set and retrieve a password locking out certain functions for the CNC. However, when this function is called again, there is a dropdown box that includes the last 11 entries into that box. If you close KMotionCNC.exe and reopen it, those entries are cleared out. I would like to clear out those entries after every input but I'm having trouble finding them. I tried searching for some of the passwords in the KMotion folder and nothing came up. I tried looking at the persist.UserData and there was nothing in there. The only thing I haven't checked so far is the gather_buffer as a potential location holding onto all those values. The issue here is that someone could put in the correct password and then someone who shouldn't have access could just look at the previous entries.
Do you know where KMotionCNC stores previous data from dialog boxes?

PBandJacob
Posts: 19
Joined: Thu Sep 02, 2021 6:02 pm

Re: Password Protect User C Programs

Post by PBandJacob » Wed Jun 29, 2022 3:58 pm

Update: I tried turning off all the autocorrect features in Windows and that did not eliminate the drop down box of previous values in the Dynomotion/KMotion input box.

User avatar
TomKerekes
Posts: 1962
Joined: Mon Dec 04, 2017 1:49 am

Re: Password Protect User C Programs

Post by TomKerekes » Thu Jun 30, 2022 2:39 pm

Recent entries are stored in PC memory in a List called Recent in the CSetValue class. See the function below in SetValue.cpp. After the Operator selects OK it is added to the head of the list. You would need to change and re-compile KMotionCNC to change this.

An alternate approach might be to use a new screen and screen script with an edit control to enter the password. KFLOP C Programs can read Screen Script Edit Controls as well as write to them. So it should be possible to clear the edit control after the password is entered.

Code: Select all

void CSetValue::OnOK() 
{
	UpdateData();

	double v;

	int result = sscanf(m_ValueString,"%lf",&v);

	if (result==1)
	{
		m_Value = v;

		POSITION pos = Recent.GetHeadPosition();
		POSITION prev=pos;
		for (int i=0; i < Recent.GetCount(); i++)
		{
			if (m_ValueString == Recent.GetNext(pos))
			{
				Recent.RemoveAt(prev);
			}
			prev = pos;
		}

		if (Recent.GetCount() >10)
			Recent.RemoveTail();

		Recent.AddHead(m_ValueString);
	}
	else
	{
		AfxMessageBox("Invalid Entry");
		return;
	}

	
	CDialog::OnOK();
}
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply