当你辛辛苦苦用DELPHI做好了一个你认为十分不错的程序,你是否想把它发布出去成为共享软件呢 做为一个共享软件,注册码肯定是少不了的,你可以通过判断程序是否注册来进行功能,时间或一些其它限制.现在就介绍一种简单的注册码制造方法.思路是这样的:程序运行时先检测注册表,如果找到注册项,则表明已经注册,如果没有找到注册项,则提示要求注册. <注册例程> 在DELPHI下新建一工程,放置Edit1,Edit2,Label1,Label2,Button1组件.具体代码如下: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Registry;//在此加上Registry以便调用注册表. type TForm1 = class(Tform) Button1: Tbutton; Edit1: Tedit; Edit2: Tedit; Label1: Tlabel; Label2: Tlabel; procedure Button1Click(Sender: Tobject); procedure FormCreate(Sender: Tobject); private Function Check():Boolean; Procedure CheckReg(); Procedure CreateReg(); { Private declarations } public { Public declarations } end; var Form1: TForm1; Pname:string; //全局变量,存放用户名和注册码. Ppass:integer; implementation {$R *.DFM} Procedure TForm1.CreateReg();//创建用户信息. var Rego:Tregistry; begin Rego:=Tregistry.Create; Rego.RootKey:=HKEY_USERS; rego.OpenKey('.DEFAULTSoftwareAngelSoftDemo',True);//键名为AngelSoftDemo,可自行修改. Rego.WriteString('Name',Pname);//写入用户名. Rego.WriteInteger('Pass',Ppass);//写入注册码. Rego.Free; ShowMessage('程序已经注册,谢谢!'); CheckReg; //刷新. end; Procedure TForm1.CheckReg();//检查程序是否在注册表中注册. var Rego:Tregistry; begin Rego:=Tregistry.Create; Rego.RootKey:=HKEY_USERS; IF Rego.OpenKey('.DEFAULTSoftwareAngelSoftDemo',False) then begin Form1.Caption:='软件已经注册'; Button1.Enabled:=false; Label1.Caption:=rego.ReadString('Name');//读用户名. Label2.Caption:=IntToStr(Rego.ReadInteger('Pass')); //读注册码. rego.Free; end else Form1.Caption:='软件未注册,请注册'; end; Function TForm1.Check():Boolean;//检查注册码是否正确. var Temp:pchar; Name:string; c:char; I,Long,Pass:integer; begin Pass:=0; Name:=edit1.Text; long:=length(Name); for I:=1 to Long do begin temp:=pchar(copy(Name,I,1)); c:=temp^; Pass:=Pass+ord(c); //将用户名每个字符转换为ASCII码后相加. end; if StrToInt(Edit2.Text)=pass then begin Result:=True; Pname:=Name; Ppass:=Pass; end else Result:=False; end; procedure TForm1.Button1Click(Sender: Tobject); begin if Check then CreateReg else ShowMessage('注册码不正确,无法注册'); end; procedure TForm1.FormCreate(Sender: Tobject); begin CheckReg; end; end. <注册器> 在DELPHI下新建一工程,放置Edit1,Edit2,Button1组件.具体代码如下: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(Tform) Button1: Tbutton; Edit1: Tedit; Edit2: Tedit; procedure Button1Click(Sender: Tobject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: Tobject); var Temp:pchar; Name:string; c:char; I,Long,Pass:integer; begin Pass:=0; Name:=edit1.Text; long:=length(Name); for I:=1 to Long do begin temp:=pchar(copy(Name,I,1)); c:=temp^; Pass:=Pass+ord(c); end; edit2.text:=IntToStr(pass); end; end. 从<注册器>中取得注册码,便可在<注册例程>中进行注册.原理是使用ORD函数取得用户名每单个字符的ASCII码值,并进行相加得到注册码.当然,这十分容易并破解,你可以用XOR进行异或操作,或者倒取反值...具体的要看你怎么实现了.总之,本文章只抛砖引玉罢了.
|
请发表评论