上一篇 | 下一篇

用Delphi3编写共享软件

发布: 2008-6-26 20:32 | 作者: admin | 来源: | 查看: 2次

判断软件是否注册

----判断软件是否注册的代码应放在应用程序主窗口的OnCreate事件中,在这一段代码中,主要完成以下功能:

判断软件注册文件是否存在及是否符合规范(可能被用户误修改);

从注册文件中读取注册密码及程序自动生成注册密码所需要的信息;

如果两者一致,则置注册成功标志,关闭主菜单中的"注册"菜单项,否则,打开"注册"菜单项。

   procedure TMainBox.FormCreate(Sender: TObject);

   var s0,s1,s2,s3:string;

//s4,s5:string为全程变量

    n1,n2:longint;

    myfile:textfile;

    users:pchar;

    i:integer;

   begin

    if not fileexists('wps2word.log') then

    begin //不存在注册文件,则没有注册

    r2.Visible:=True; //允许"注册"菜单项

    Randomize; //初始化随机数序列

    n1:=random(100000000);

//产生一个8位以内的整数

    s4:=inttostr(n1);

//假设输入的注册密码为s4

    s5:=inttostr(n1 +7)

//假设程序生成的注册密码为s5,令s4<>s5

    end

    else begin //存在注册文件的处理

    assignfile(myfile,'wps2word.log');

    reset(myfile);

//读取用户注册信息及注册密码

    if not eof(myfile) then readln(myfile,s0);

    if not eof(myfile) then readln(myfile,s1);

    if not eof(myfile) then readln(myfile,s2);

    if not eof(myfile) then readln(myfile,s3);

    if not eof(myfile) then readln(myfile,s4);

    if not eof(myfile) then readln(myfile,s5);

    closefile(myfile);

    if (length(s1)< 10) or (length(s2)< 10)

or (length(s3)< 10) or (length(s5)< 15) then

    begin

//文件格式有误,则删除注册文件,并退出

     deletefile('wps2word.log');

     r2.Visible:=True; //允许"注册"菜单

     Exit; //退出

end;

i:=255;

getmem(users,255);

getusername(users,i); //获得Windows用户名

    s0:='jdk' +users +'ue28'; //避免用户名太短

    freemem(users);

s1:=trim(copy(s1,10,length(s1) -9)); //单位全称

    s2:=trim(copy(s2,10,length(s2) -9)); //用户姓名

    s5:=trim(copy(s5,8,length(s5) -7));

//注册密码(待核对)

    s1:=s2 +' xwplskf' +s1 +'ruieo';

//合成单位全称和用户姓名

    n1 := DiskSize(3) div 1024 ; //C盘容量

    n2 :=1 ;

    for i:=1 to length(s1) do

    n2:=abs((ord(s1[i]) *n2 + $f77)) mod 1000000;

    for i:=2 to length(s0) do

    n2:=abs((ord(s0[i]) *n2 +n1)) mod 1000000;

    n2:=10504007 +abs((n2 +n1) *(length(s1) +length(s0)));

    n2:=strtoint(copy(inttostr(n2),1,8)); //登录码

    //以下部分生成注册密码

    n2:=120873762 +abs((n2 div 133) *171 xor 39639421);

    s1:=copy(inttostr(n2),1,8);

    s2:='73461852'; //移位变换

    s4:=''; //S4为程序自动生成的注册密码

    for i:=1 to 8 do

    s4:=s4 +s1[ord(s2[i]) -ord('1') +1〗;

    //核对注册文件和自动生成的注册密码是否致

    if strtoint(s4) *7=strtoint(s5) *7 then

    r2.Visible:=False //一致

    else begin // 不一致

    deletefile('wps2word.log'); //删除注册文件

    r2.Visible:=True; //允许"注册"菜单项

      end;

    end;

   end;

字号: | 推荐给好友

32/3<123>

评分:0

我来说两句

网络推荐