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

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from an encrypted "password" registration-key file,      *)
  5. (* using one "embedded" encryption-code string and one user-entered   *)
  6. (* "password" encryption-code string.                                 *)
  7. (*                                                                    *)
  8. (* NOTE: Before you can compile this program, you must first          *)
  9. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  10. (*       the two "random" encryption-code binary data files. Then     *)
  11. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  12. (*       these two binary data files to "object" format files.        *)
  13. (**********************************************************************)
  14.  
  15. program ReadFlxKeyDemo3;
  16. uses
  17.   Crt,
  18.   FlxKey;
  19.  
  20. type          (* 20 character string definition.                      *)
  21.   st20    = string[20];
  22.  
  23.               (* 20 character string-pointer definition.              *)
  24.   st20Ptr = ^st20;
  25.  
  26. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  27.               (* the difference in days between the current date and  *)
  28.               (* the date encrypted into the registration-key file.   *)
  29.   DaysOld,
  30.  
  31.               (* This variable is used to check for errors returned   *)
  32.               (* by ReadFlxKey routine.                               *)
  33.   ErrorCode : word;
  34.  
  35.               (* Encryption-code string-pointer, used to decrypt the  *)
  36.               (* data in the encrypted registration-key file.         *)
  37.   Ecode1Ptr  : st20Ptr;
  38.  
  39.               (* User "password" encryption-code string.              *)
  40.   stPassword : st20;
  41.  
  42.               (* This is the full path/filename of the encrypted      *)
  43.               (* registration-key file to be decrypted.               *)
  44.   RegKeyName : st79;
  45.  
  46.               (* Record variable to hold the data decrypted from the  *)
  47.               (* encrypted registration-key file.                     *)
  48.   TempKeyRec : FlxRec;
  49.  
  50.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  51.  
  52.               (* "Fake" procedure that contains first encryption-code *)
  53.               (* string.                                              *)
  54.   procedure Ecode1Data; external;
  55.   {$L ECODE1.OBJ}
  56.  
  57.   {$F-}       (* Turn off "FAR" declaration.                          *)
  58.  
  59.               (* Main program execution block.                        *)
  60. BEGIN
  61.               (* Initialize the encryption-code string pointer to     *)
  62.               (* it's data.                                           *)
  63.   Ecode1ptr := addr(Ecode1Data);
  64.  
  65.               (* Clear the temporary key-record variable.             *)
  66.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  67.  
  68.               (* Full path/filename for the encrypted registration-   *)
  69.               (* key file to be decrypted.                            *)
  70.   RegKeyName := 'DEMO3.KEY';
  71.  
  72.               (* Enter User "password" encryption-code string.        *)
  73.   writeln;
  74.   write('Enter Password : ');
  75.   readln(stPassword);
  76.  
  77.               (* Decrypt the registration-key file, and retreive it's *)
  78.               (* data.                                                *)
  79.               (* NOTE: A 10 second delay and message are present in   *)
  80.               (*       the un-registered copy of the FlxKey unit.     *)
  81.   ReadFlxKey(Ecode1Ptr^, stPassword, RegKeyName, TempKeyRec, DaysOld,
  82.              ErrorCode);
  83.  
  84.               (* Clear the screen.                                    *)
  85.   clrscr;
  86.   writeln;
  87.  
  88.               (* Check for errors.                                    *)
  89.   if (ErrorCode <> 0) then
  90.     case (ErrorCode AND $FF) of
  91.        1 : writeln(' Error! One or more encryption-codes are blank.');
  92.        2 : writeln(
  93.                 ' Error! Filename for registration-key file is blank.');
  94.        3 : writeln(' Error! Password is NOT correct!');
  95.  
  96.               (* I/O error!                                           *)
  97.       16 : begin
  98.              writeln(' I/O error = ', (ErrorCode shr 8));
  99.  
  100.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  101.               (* as there are many types of errors to check for.      *)
  102.              case (ErrorCode shr 8) of
  103.                  2 : writeln(' File not found.');
  104.                  3 : writeln(' Path not found.');
  105.                  4 : writeln(' Too many files open.');
  106.                  5 : writeln(' File access denied.');
  107.                100 : writeln(' Disk read error.');
  108.                103 : writeln(' File not open')
  109.              end  (* case (ErrorCode shr 8) of                        *)
  110.            end
  111.     end       (* case (ErrorCode AND $FF) of                          *)
  112.   else
  113.               (* Else NO errors occurred.                             *)
  114.     begin
  115.               (* Display the decrypted registration-key data.         *)
  116.       writeln('Key is ', DaysOld, ' days old');
  117.       writeln;
  118.       with TempKeyRec do
  119.         begin
  120.           writeln(' FirstName    = ', FirstName);
  121.           writeln(' LastName     = ', LastName);
  122.           writeln(' Address1     = ', Address1);
  123.           writeln(' Address2     = ', Address2);
  124.           writeln(' Address3     = ', Address3);
  125.           writeln(' AppName      = ', AppName);
  126.           writeln(' Version      = ', Version);
  127.           writeln(' Serial Num   = ', Serial);
  128.  
  129.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  130.               (* can be used to manipulate "packed date" data.        *)
  131.           writeln(' Packed Date  = ', Date);
  132.  
  133.           writeln(' Access Level = ', Access)
  134.         end
  135.     end
  136. END.
  137.  
  138.  
  139.