Establish registration mechanisms for application software with DEPHI
How to protect your own software is not the problem of unauthorized stealing, always plaguing every programmer. There are many ways to protect software in the world, mainly using encryption (such as plus software dog) or software registration. Using software dogs and other encryption methods, although its protection is most effective, there is a certain impact on the normal use of authorized users, and software is relatively complicated and is less employed in practical use. The registration method is the most popular and widely used method. Although there are many universal software that can be easily solved by their registration codes, it is concerned that the independent programmer is the application design for a particular application. The use of registration mechanisms is most economical and convenient, and it is very effective within a certain range. In actual work, the author has widely used software registration methods to effectively maintain the rights of software. The function of the DEPHI software is extremely powerful and is deeply affected by programmers. Software developed with DepHi can easily join the registration mechanism. The author adds the registration mechanism with friends to exchange experience with the software developed in Dephi. To achieve software registration mechanism, you need to solve the following problems: 1. How to join the registration test, determine if the software is registered; 2. How to hide the registration code, and whether the logo registered; 3, how to limit the software without registration Use time or number of times; 4. For normal users, it should not cause inconvenience. For the above four problems, how to hide the registration code and whether the logo registered is the key. In Windows95, Win95 itself and most of the applications are placed in the registry, so the data within the registry is extremely large and complicated. If the registration flag is hidden in a certain angle of the registry, you want to find it and understand it is extremely difficult. So we can use this, set up a keyword from the name on a branch of the registry, and store the registration mark data of your software here. The following is a flow block diagram of the entire registration mechanism:
As can be seen from the figure, the entire registration mechanism is mainly composed of two parts: check and registration. By checking the logo value, the software has been registered; if there is no registration, it is necessary to see if it allows the number of times to be used; if the number of times available is used, it should prompt the user to enter the registration code, register only. When the registration code entered is correct, let the user continue to use the software, and the flag is set to have been registered so that the user is permanently used; otherwise the number of times that is allowed is not reached, and the number of times will be added; if the user registration input registration code error Or refuse to register, close the software directly and reject it to continue. Of course, when the number of software allows the number of uses is not reached, the user will provide a chance to provide opportunities to register. The following is the program code and annotation of the author to establish a registration mechanism in actual development.
Assuming that the software's main program window is Form1, this segment code is placed in the Form1.create event. code show as below:
Procedure TFORM1.FORM1CREATE (Sender: Tobject); varre_id: integer; registertemp: Tregistry; inputstr, get_id: string; dy, clickedok: boolean; begin dy: = false; // Software has arrived period, and whether it is allowed to continue The logo, when the value is false is allowed. registerTemp: = TRegistry.Create; // ready to use the registry with registerTemp do begin RootKey: = HKEY_LOCAL_MACHINE; // stored in the root under if OpenKey ( 'Software / Microsoft / Windows / CurrentVersion / Mark', True) then // build A directory, store the logo value. Of course, it can also be stored in existing directories. How is it, it is difficult to find it? Begin if valueexists ('GC_ID') THEN BEGIN / / The value of GC_ID as a flag, first determined whether it exists? RE_ID: = Readinteger ('gc_id'); // Reads the flag value IF (RE_ID <> 0) and (RE_ID <> 100) The begin // If the flag value is 0, the registration is explained. // If not 0 and the value is less than 100, the number of times that allows usage has not been reached although not registered. RE_ID: = RE_ID 5; // Allow the maximum value of 100, each time 5, then only 20 times. WriteInteger ('gc_id', re_id); // Write the updated flag value in the registry. End; if RE_ID = 100 Then DY: = true; // If the value has arrived 100, it should be registered. ELSE WRITEINTEGER ('GC_ID', 5); // Establish a flag, and set the initial flag value. End; if Dy Then Begin // If the DY value is TRUE, you should prompt the user to enter the registration code for registration. Clickedok: = INPUTQUERY ('You are using non-registration software, please enter the registration code:', '', inputstr); if Clickedok The begin get_id: = INTOSTR (27593758 * 2); // Registration code is 55187516, of course you can join More miscellaneous algorithms. If get_id = inputstr1n becom writeinteger ('gc_id', 0); // If the entered registration code is correct, set the flag value to 0, that is, registered.
CloseKey; Free; Else Begin // If you entered the registration code error, you should make a prompt and refuse to let it continue to use Application.MessageBox ('Registration code error! Please contact the author!', 'Warning box', MB_OK; CloseKey Free; Application.Terminate; // Abort process running, refuse to continue to use end; END ELSE begin // If the user does not enter a registration code, it should also be prompted and refuse to let it continue to use Application.MessageBox. Contact, use registration software! ',' Warning box ', MB_OK; closekey; free; application.terminate; end; end; end; end; (Note: Method for registering by menu) Sign up with this segment prompting users to register Lei, this is not available here.)
The above program code has been run in the DEPHI3.0 / WIN95 environment and verified in practical use. For legal users, such a mechanism, as long as it enters the registration code, it is possible to increase its daily use burden; and the illegal user is not allowed to reload the registration code or reload the Windows95, it will exceed the number of times. Will not be able to continue. Of course, there are still many places in practical applications to further strengthen anti-cracking ability, welcome friends to make criticism and guidance.
(Fujian Yang Jianshan)