How to use EALocker? - In the source you'll find the Headers\LockedEA.mqh file, there will be the all needed source, to protecr your own EA. - The password and your unique encryption key is in your Metatrader "Experts" tab. - You can generate unique licenses to you users, and you need to give the license string to you users too. Or your .lic file, or the content in the .lic file, and you can get that license string in your EA input field. - Need some in program modify on header, OnInit and program body. 1. You need only this 3 source: #include "Headers\\math_utils.mqh" #include "Headers\\Crypting.mqh" #include "Headers\\Functions.mqh" 2. need to implement "CheckLicenseString" function in your EA (included) 3. Should to use your directory structure 4. Must use your private encryption key, and replace it in your EA in the init() function 5. Should modify license warning messages 6. Need to use same "EAID" as you set in your license key 7. You can change checking parameters in CheckLicenseString if you want: ... example: there you can delete EAID and UserAccount checking, and you got only a time limited version if((License.Expiredate>TimeLocal()) && (License.EAID==EAID) && (License.userAccount==UserAccount) ){ checkok=true; }else{ checkok=false; } ... Full list of modifications need in your program: * Variables: //****************************************** HEADER ********************************************************** //Input fields for EA input string p_LicenseFileName = ""; // License file for manual testing input string p_LicenseData = ""; // License data for manual testing string p_EAID = "EA-Identifier"; // EA Identifier string p_UserID = "TestUser"; // User Identifier (default: account number) //EA data string EAID = p_EAID; string UserAccount = p_UserID; string LicenseFileName = p_LicenseFileName; string LicenseData = p_LicenseData; bool isFreeLicense = false; string p_password = ""; int debuglevel = 0; //License data struct LicenseStruct{ string EAID; string userAccount; datetime Expiredate; }; LicenseStruct License; #include "Headers\\math_utils.mqh" #include "Headers\\Crypting.mqh" #include "Headers\\Functions.mqh" //****************************************** HEADER END ********************************************************** *** OnInit(): //****************************************** ONINIT ********************************************************** /* Need to check license */ FolderCreate("EnkiSoft",true); // <- You can use your Directories string p_BaseDirectory="Enkisoft\\EALock\\"; // <- You can use your Sub Directories FolderCreate(p_BaseDirectory,true); string EADir=p_BaseDirectory; string keystr="A5FF53BABA1234FAA18765DECABAFA01A5FF53BABA1234FAA18765DECABAFA01"; // <- You MUSt use YOUR own unique Encryption key (you generated the EALocker) //you can fid it in your computer: //C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\Common\Files\Enkisoft\EALock\EALocker.key //Check License File bool LicenseOk = False; if(p_LicenseFileName!=""){ Print("Check License: ",p_LicenseFileName); int fHandle=FileOpen(EADir+p_LicenseFileName,FILE_READ|FILE_SHARE_READ|FILE_ANSI|FILE_TXT|FILE_COMMON,";",CP_UTF8); if(fHandle!=INVALID_HANDLE){ string LicenseSTR = FileReadString(fHandle); FileClose(fHandle); Print("Licende data:",LicenseSTR); if(!CheckLicenseString(LicenseSTR)){ //MessageBox("Invalid license!",p_LicenseFileName,MB_OK|MB_ICONWARNING); }else{ LicenseOk = true; } }else{ MessageBox("License file not found.",p_LicenseFileName,MB_OK|MB_ICONWARNING); Print("License file not found: ",p_LicenseFileName); } }else{ //If no file, check pasted license data if(!CheckLicenseString(p_LicenseData)){ //MessageBox("Invalid license!",p_LicenseData,MB_OK|MB_ICONWARNING); }else{ LicenseOk = true; } } //Additional License information if (!LicenseOk){ string MatchInfo; if (License.EAID == EAID){ MatchInfo = "EAID is match. \n"; }else{ MatchInfo = "EAID is NOT match! \n"; } if (License.userAccount == UserAccount){ MatchInfo += "User Account is match. \n"; }else{ MatchInfo += "User Account is NOT match! \n"; } if (License.Expiredate >= TimeLocal() ){ MatchInfo += "Date is not expired. \n"; }else{ if (License.Expiredate==0){ MatchInfo += "Date is INVALID! \n"; }else{ MatchInfo += "Date is EXPIRED! \n"; } } Print("License is INVALID! ",MatchInfo); MessageBox("License is INVALID! \n\n"+MatchInfo,"License check...",MB_OK|MB_ICONERROR); } if (!LicenseOk){ return (INIT_FAILED); }else{ return (0); } //****************************************** ONINIT END ******************************************************* *** Functions anywhere in body: //****************************************** FUNCTIONS ********************************************************** bool CheckLicenseString(string LicenseSTR){ bool checkok=false; //Default License.EAID = ""; License.userAccount = ""; License.Expiredate = 0; if(debuglevel>2) Print("Check License data:",LicenseSTR); string Dec_Str = DecodeStr( LicenseSTR,CRYPT_AES256); StringToUpper(Dec_Str); //Uppercase string Str_eaid=""; string Str_account=""; string Str_expire=""; datetime expire=0; if(debuglevel>2) Print("Decoded data:",Dec_Str); string EncLic[10]; ushort u_sep=StringGetCharacter(":",0); int rows=StringSplit(Dec_Str,u_sep,EncLic); if(rows>2){ Str_eaid = EncLic[0]; if(debuglevel>2) Print("EAid:",Str_eaid); Str_account = EncLic[1]; if(debuglevel>2) Print("Account:",Str_account); Str_expire = EncLic[2]; if(debuglevel>2) Print("Expire:",Str_expire); MqlDateTime dExpire; dExpire.year = (int)StringToInteger( StringSubstr(Str_expire,0,4) ); dExpire.mon = (int)StringToInteger( StringSubstr(Str_expire,4,2) ); dExpire.day = (int)StringToInteger( StringSubstr(Str_expire,6,2) ); expire = dExpire.year*10000+dExpire.mon*100+dExpire.day; License.EAID = Str_eaid; License.userAccount = Str_account; License.Expiredate = StructToTime( dExpire ); Print("License number and expire:",StringConcatenate(Str_eaid,":",Str_account,":",TimeToString(License.Expiredate,TIME_DATE) ) ); }else{ Print("Decode error, recoded rows:",rows,", need: 3"); } //If decrypt fail if ((expire==0)||(Str_eaid=="")||(Str_account=="")||(Str_expire=="")){ Print("License data:",LicenseSTR); Print("Decoded data:",Dec_Str); checkok=false; }else{ //If decrypt success, check data StringToUpper(EAID); StringToUpper(UserAccount); if(debuglevel>2) Print("License.EAID=",License.EAID," ,EAID=",EAID,", License.userAccount=",License.userAccount,", UserAccount=",UserAccount); if((License.Expiredate>TimeLocal()) && (License.EAID==EAID) && (License.userAccount==UserAccount) ){ checkok=true; }else{ checkok=false; } } return checkok; } //****************************************** FUNCTIONS END *******************************************************