home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FLXKEY10.ZIP / MAKEKEY3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  5.8 KB  |  141 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to create *)
  4. (* an encrypted "password" registration-key using one "embedded"      *)
  5. (* encryption-code and one user-entered "password" encryption-code.   *)
  6. (*                                                                    *)
  7. (* NOTE: Before you can compile this program, you must first          *)
  8. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  9. (*       the two "random" encryption-code binary data files. Then     *)
  10. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  11. (*       these two binary data files to "object" format files.        *)
  12. (**********************************************************************)
  13.  
  14. program MakeFlxKeyDemo3;
  15. uses
  16.   FlxKey;
  17.  
  18. type          (* 20 character string definition.                      *)
  19.   st20    = string[20];
  20.  
  21.               (* 20 character string-pointer definition.              *)
  22.   st20Ptr = ^st20;
  23.  
  24. var           (* This variable is used to check for errors returned   *)
  25.               (* by CreateFlxKey routine.                             *)
  26.   ErrorCode  : word;
  27.  
  28.               (* 1 encryption-code string-pointer.                    *)
  29.   Ecode1Ptr   : st20Ptr;
  30.  
  31.               (* User "password" encryption-code.                     *)
  32.   stPassword : st20;
  33.  
  34.               (* Full path/filename of the encrypted registration-key *)
  35.               (* file to be created.                                  *)
  36.   RegKeyName  : st79;
  37.  
  38.               (* This variable is used to pass the user-data to the   *)
  39.               (* CreateFlxKey routine.                                *)
  40.   TempKeyRec : FlxRec;
  41.  
  42.   {$F+}       (* Declare the following procedure as "FAR".            *)
  43.  
  44.               (* "Fake" procedure that contains first encryption-code *)
  45.               (* string.                                              *)
  46.   procedure Ecode1Data; external;
  47.   {$L ECODE1.OBJ}
  48.  
  49.   {$F-}       (* Turn off "FAR" declaration.                          *)
  50.  
  51.               (* Main program execution block.                        *)
  52. BEGIN
  53.               (* Initialize the encryption-code pointer to it's       *)
  54.               (* string data.                                         *)
  55.   Ecode1ptr := addr(Ecode1Data);
  56.  
  57.               (* Clear the temporary key-record variable.             *)
  58.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  59.  
  60.               (* Assign data to temporary key-record.                 *)
  61.   with TempKeyRec do
  62.     begin
  63.               (* 20 char space is available for first-name.           *)
  64.       FirstName := 'John';
  65.  
  66.               (* 30 char space is available for last-name.            *)
  67.       LastName  := 'Smith';
  68.  
  69.               (* 30 char space is available for Address1.             *)
  70.       Address1  := '1234 AnyPlace Road,';
  71.  
  72.               (* 30 char space is available for Address2.             *)
  73.       Address2  := 'BigCity BigPlace,';
  74.  
  75.               (* 30 char space is available for Address3.             *)
  76.       Address3  := 'BigCountry, BigZip';
  77.  
  78.               (* 20 char space is available for application-name.     *)
  79.       AppName   := 'Amazing Program';
  80.  
  81.               (* Version can be assigned any valid word data.         *)
  82.       Version   := 310;
  83.  
  84.               (* Serial can be assigned any valid longint data.       *)
  85.       Serial    := 1234567890;
  86.  
  87.               (* Date can be assigned any valid "packed" date/time.   *)
  88.               (* If a value of 0 is assigned to Date, CreateFlxKey    *)
  89.               (* routine will assign the current date/time to this    *)
  90.               (* variable in "packed" date/time format. Use TP's      *)
  91.               (* standard "PackTime" and "UnPackTime" routines to     *)
  92.               (* manipulate this data.                                *)
  93.       Date      := 0;
  94.  
  95.               (* Access level can be assigned a number from 0..65,535 *)
  96.       Access    := 1234
  97.     end;
  98.  
  99.               (* Filename for the encrypted registration-key to be    *)
  100.               (* created.                                             *)
  101.   RegKeyName := 'DEMO3.KEY';
  102.  
  103.               (* Prompt for user "password" encryption-code string.   *)
  104.   writeln;
  105.   write('Enter Password : ');
  106.   readln(stPassword);
  107.  
  108.               (* Create encrypted registration-key using the data     *)
  109.               (* assigned to TempKeyRec.                              *)
  110.   CreateFlxKey(TempKeyRec, Ecode1Ptr^, stPassword, RegKeyName, ErrorCode);
  111.  
  112.               (* Move cursor down one line.                           *)
  113.   writeln;
  114.  
  115.               (* Check for errors.                                    *)
  116.   case (ErrorCode AND $FF) of
  117.      0 : writeln(' Sucessful key creation! No errors.');
  118.      1 : writeln(' Error! One or more encryption-codes are blank.');
  119.      2 : writeln(' Error! Filename for registration-key file is blank.');
  120.  
  121.               (* I/O error!                                           *)
  122.     16 : begin
  123.            writeln(' I/O error = ', (ErrorCode shr 8));
  124.  
  125.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  126.               (* as there are many types of errors to check for.      *)
  127.            case (ErrorCode shr 8) of
  128.                2 : writeln(' File not found.');
  129.                3 : writeln(' Path not found.');
  130.                4 : writeln(' Too many files open.');
  131.                5 : writeln(' File access denied.');
  132.              101 : writeln(' Disk write error.');
  133.              103 : writeln(' File not open');
  134.              150 : writeln(' Disk is write-protected')
  135.            end  (* case (ErrorCode shr 8) of                          *)
  136.          end
  137.   end         (* case (ErrorCode AND $FF) of                          *)
  138. END.
  139.  
  140.  
  141.