Recursive Procedure lazarus / 62-General ---------------------------------------------------------------------- J-G · 2022-03-18 16:54 I'm probably going about this isssue in a totally incorrect way but I tend to learn by making mistakes! I've never previously needed to think about IP Protection but my current project will go to a third party that I don't know personally for testing & review so I thought that it was about time I incorporated some sort of 'Pass Code' to at least look as if I care The logic of creating a number from a string of characters is no problem nor retreiving same for comparison. Nor are the issues of getting the 'user' details upon first running the program, saving those and getting them back on subsequent runs.  What I can't do is get the [Pass Code] dialogue to appear and be editable on subsequent runs. I eventually hit upon the idea to call the testing routine,    as in: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Get_PassCode;begin  Form1.Test_Panel.show;  GoodToGo := false;  Repeat    Form1.Pass_Code_TestEditingDone(Nil);  until GoodToGo;  Form1.Test_Panel.Hide;   Form1.ThreadFormList.Enabled:=False;end;  The test procedure takes the number typed into a TEdit and compares it to the known code - viz.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Pass_Code_TestEditingDone(Sender: TObject);begin  Pass_Test := StrToFloat(Pass_Code_Test.Text);  GoodToGo  := (Pass_Code-Pass_Test = 0);  If Pass_Test = 0 then    begin      Application.Terminate;    end;   If GoodToGo then    begin      Form1.Hello_Label.Caption:='Thanks';      Form1.Hello_Label.Color:=clOlive;      Form1.User_FirstName_Label.Caption:=UserName;      Form1.User_FirstName_Label.Show;      Form1.Hello_Label.Show;      Application.ProcessMessages;       Sleep(1000);       KillPanel;      Form1.Test_Panel.Hide;      Form1.ThreadFormList.Enabled:=True;    end  else    begin      Form1.Hello_Label.Caption:='ERROR';      Form1.Hello_Label.Color:=clRed;      Form1.Hello_Label.Show;    end;end;  As you can see, the TEdit is on a TPanel which can be shown or hidden and that part works as expected. What happens is that if I 'initiallize' Pass_Code_Test.Text the panel doesn't appear for entry/editing and if I don't initiallize it then I get an 'Error:  "" is an invalid float' and the panel appears after clicking [OK] (The 'KillPanel' is  just a fancy way to make it deminish in size rather than just vanish as in .Hide) ---------------------------------------------------------------------- Bart · 2022-03-19 13:04 I would do it like this (assuming that all of this is done on 1 form): In Get_PassCode: - show the panel - disable all other components on the form In Pass_Code_TestEditingDone: - use TryStrToFloat to avoid exceptions - if (Pass_Code-Pass_Test = 0) then hide the panel en show enable the other controls again, then proceed with whatever you want to do I think I would prefer another solution where asking for the Pass Code was done on a separate for, which was shown using ShowModal, and the calling routine will check the value of ModalResult (which you can set to a value that indicates failure inside the OnEditingDone of the Edit in which yoy let the user type the Pass Code. Bart ---------------------------------------------------------------------- J-G · 2022-03-19 16:49 Thanks for your Input  Bart & Jamie. With the unusual lack of response for two days  -  (this forum usually gets a positive response within hours  )  I've been working on a completely different aproach. I did say that I thought my basic concept was flawed! So as not to clutter up this thread I'll start another with a different approach. ---------------------------------------------------------------------- mas steindorff · 2022-03-19 19:04 just one comment: A simple program like processHacker can scan a program and list it's embedded strings for the user. You shouldn't store your pass code as a single string. Mas ---------------------------------------------------------------------- J-G · 2022-03-19 19:19 Quote from: mas steindorff on March 19, 2022, 08:04:25 pmjust one comment: A simple program like processHacker can scan a program and list it's embedded strings for the user. You shouldn't store your pass code as a single string. Mas Good point - and no I don't store it, I calculate it on the fly and compare it to the entered value (which isn't stored either). ---------------------------------------------------------------------- dbannon · 2022-03-19 23:01 While the topic of such protection has been discussed to death, I must still comment. You need to supply the binary to someone to test, and the passcode. You are worried that someone may give your work to someone else ?  Whats to stop them also handing the passcode on ? If its being supplied for review, maybe a time limit would work better, "this app will stop working after April 2022" ? Davo ---------------------------------------------------------------------- J-G · 2022-03-19 23:24 Quote from: dbannon on March 20, 2022, 12:01:14 amIf its being supplied for review, maybe a time limit would work better, "this app will stop working after April 2022" ? Davo That is EXACTLY the approach I am now taking Davo, thanks for  the confirmation that I'm moving in the right direction There's no real 'worry' I don't do [Worry]    If the program were to be passed on, - and it's no great shakes if it is - the first thing that happens on running it is a request for a 'Data Directory' and the second is confirmation of the User Details. If they are changed then the PassCode will not be the same. To be honest, I don't even think that it might be passed on and this is just a nerd's excercise to prove to myself that some sort of protection is possible and that 'passing off' is traceable. ---------------------------------------------------------------------- J-G · 2022-03-20 18:50 Continuing my research into 'simple' program protection, I've come across an oddity. My logic tells me that these two code fragments ought to return the same number : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   N := Length(S);  for i := 1 to length(S) do     N := N + Ord(S[1]) * i;  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   N := Length(S);  for i := 1 to length(S) do    begin      X := S[i];      O := Ord(X) * i;      N := N+O;    end;  ... but they don't  -  and I can't see why.  The var declarations are : N : Longword; O : Word; X : Char; i : byte; I'd appreciate some guidance as to the failure in my logic! ---------------------------------------------------------------------- wp · 2022-03-20 19:00 There's an S[1] in the first fragment (instead of S) ---------------------------------------------------------------------- rvk · 2022-03-20 19:05 Quote from: wp on March 20, 2022, 08:00:31 pmThere's an S[1] in the first fragment (instead of S) You can use nobbc-tag  to quote [i]   See: There's an S[1] in the first fragment (instead of S[i]) ---------------------------------------------------------------------- J-G · 2022-03-20 23:13 Quote from: wp on March 20, 2022, 08:00:31 pmThere's an S[1] in the first fragment (instead of S) D'oh!   -  What a pillock I am!! Such an obvious mistake, and I can't even imagine how I first typed a '1' rather than 'i' and second how I didn't see it on the many times I reviewed the code  At least I now know that my logic isn't flawed ( well, in this instance!).