This encryption method is divided into three parts:
1. Determine the content of the setting dialog based on the search results for the registry.
2. If you use it for the first time, set a new password; if you have set a password, verify it.
3. A password transformation applet (much more complicated than the original one). Of course, if you need to modify the password function, just change the password setting part.
1. When the program starts, search the registry to determine whether there is a password to determine the display content of the window. However, the following statement should be made before use:
Add TRegistry to user and add the following form variables to the var declaration:
TheReg: TRegistry;
KeyName,ValueStr,tempStr:String;
PRocedure TfrmPass.FormShow(Sender: TObject);
Begin
TheReg := TRegistry.Create;
try TheReg.RootKey := HKEY—LOCAL—MACHINE;
KeyName := ′SOFTWARE/MypassWord′;
//If this key is available, it will be opened; if it does not exist, it will be created.
if TheReg.OpenKey(KeyName, True) then begin
tempStr:=ExtractFileName(application.ExeName); //Read password
ValueStr:=TheReg.ReadString(tempStr);
// If the password is not empty, modify the form to verify the password
if ValueStr<>'' then begin
edit2.Visible:=false; frmPass.Caption:=′Verify password′;
edit1.SetFocus; OK.Caption:=′Determine'; end
// If the password is empty, modify the form to set password dialog box
else begin
showmessage(′Please set password for the first time!′);
edit2.Visible:=true; frmPass.Caption:=′Please set a new password′;
edit1.SetFocus; OK.Caption:='Set';
end; TheReg.CloseKey; end;
Finally TheReg.Free; end; end; end;
2. The button's response code: includes the new password and the verification password.
procedure TfrmPass.OKClick(Sender: TObject);
Begin
//Judge the existing password based on whether Edit2 is displayed or not, and verify
if edit2.Visible=false then begin
if pass(edit1.text)=ValueStr then begin
showmessage('The password is correct!'); end
else begin
showmessage('The password is incorrect! No permission to operate!');
halt; end; end //No password, set new password
else begin
if edit1.text=edit2.text then begin
TheReg := TRegistry.Create;
TheReg.RootKey := HKEY—LOCAL—MACHINE;
KeyName := ′SOFTWARE/Mypassword′;
if TheReg.OpenKey(KeyName, True) then
TheReg.WriteString(tempStr,pass(edit1.text));
TheReg.CloseKey; end
else begin
showmessage('The password typed again is inconsistent, please re-enter!');
edit1.text:=′′; edit2.text:=′′;
edit1.SetFocus; end; //Please the next operation...
end; end;
3. Password conversion program: Be careful to pre-defined.
In my opinion, this transformation mini program is not very complicated. It only undergoes two transformations, but it will take some effort to decipher. Readers can also use other mathematical functions to perform more complex transformations.
function pass(pstr:string):string;
var str,str1:string;
i,j:integer;
Begin
str:=pstr;
for i:=1 to length(str) do begin
//Please the first change
j:=(i*i*i mod (i+20))+(i*i mod (i+10))+i*2+1;
str1:=str1+chr(ord(str[i])+j); //The second transformation
j:=(i*i*i mod (i+10))+(i*i mod (i+20))+i*2+1;
str1:=str1+chr(ord(str[i])+j); end;
pass:=str1;
end;