⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwdfunc.pas

📁 1. 直接安装并运行案例程序   运行“安装程序”文件夹中的setup.exe文件
💻 PAS
字号:
unit pwdFunc;
interface
uses SysUtils,Dialogs;
const
   C1 = 52845;
   C2 = 22719;
var
   userName:string;
function Encrypt(const S: String; Key: Word): String; //字符串加密函数
function Decrypt(const S: String; Key: Word): String; //字符串解密函数
function checkIt(const n:string;const p:string):integer;//根据配置文件和字符串加密解密算法对用户名和密码进行验证
function createAFile:integer;
function getUserName:String;export;
implementation
function getUserName:string;export;
begin
   result:=userName;
end;

{字符串加密函数的实现}
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
  setLength(result,length(s));
  for I := 1 to Length(S) do
  begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(Result[I]) + Key) * C1 + C2;
  end;
end;
{字符串解密函数的实现}
function Decrypt(const S: String; Key: Word): String;
var
  I: byte;
begin
  setLength(result,length(s));
  for I := 1 to Length(S) do
  begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(S[I]) + Key) * C1 + C2;
  end;
end;
function checkIt(const n:string;const p:string):integer;
var
   f:file;                                 //文件类型变量
   s1,s2,s3:string[60];
   nr:integer;                             //读出的字节数
begin
   assignFile(f,'sys.ini');                //文件类型变量和配置文件关联
   reSet(f,1);                             //对文件初始化
   repeat
      blockRead(f,s1,12,nr);
      blockRead(f,s2,12,nr);
      blockRead(f,s3,12,nr);
      {为读出的字符串解密}
      s1:=Decrypt(s1,12345);
      s2:=Decrypt(s2,12345);
      s3:=Decrypt(s3,12345);
      {用户名和密码正确}
      if (s1=n) and (s2=p) then
      begin
         closeFile(f);                    //关闭文件
         userName:=s1;
         result:=strToint(s3);
         exit;
      end;
   until (nr=0);                         //读到文件末尾
   //closeFile(f);
   result:=0;
end;

function createAFile:integer;
var
   f:file;
   buf,s1,s2,s3:string[60];
   size:longint;
   nr:integer;
begin
   assign(f,'sys.ini');
   reWrite(f,1);
   buf:='admin';
   buf:=Encrypt(buf,12345);
   blockWrite(f,buf,12);
   buf:='manage';
   buf:=Encrypt(buf,12345);
   blockWrite(f,buf,12);
   buf:='1';
   buf:=Encrypt(buf,12345);
   blockWrite(f,buf,12);
   closeFile(f);
   reSet(f,1);
   repeat
      blockRead(f,s1,12,nr);
      blockRead(f,s2,12,nr);
      blockRead(f,s3,12,nr);
   until (nr=0);
   closeFile(f);
   s1:=Decrypt(s1,12345);
   result:=1;
end;

end.
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -