CT83 Posted April 28, 2016 Share Posted April 28, 2016 (edited) I have coded a snippet to ensure that my software runs only on systems that i have registered in my database and for that use the unique hardware id and then carry out conditional statements to check if the stored hardware id and the current hardware id of the system match. but the following code still says that the strings are not equal even when the strings clearly appear equal #include <Crypt.au3> #include <date.au3> #include <MsgBoxConstants.au3> #include <APIDiagConstants.au3> #include <WinAPIDiag.au3> Global $EncryptionPassword = InputBox("Enter the Password", "Enter the Encryption Password ", "", "",- 1, -1) Global $CustomerID=InputBox("Enter the Customer ID", "Enter the Customer ID to Generate Key for ", "", "",- 1, -1) Global $Expiry_Date2 = InputBox("Enter Desired Expiry Date", "Enter the Desired Expiry Date to generate a key for ", "YYYY/MM/DD", "",- 1, -1) ;~ Global $EncryptionPassword="cybertech83" Global $hardware1 = InputBox("Enter Desired Hardware ID", "Enter the Hardware ID to generate a key for ", "{XXXX-XXXX-XXXX-XXXX-XXXX}", "",- 1, -1) ;~ Global $hardware1 = _WinAPI_UniqueHardwareID($UHID_All) & @CRLF Global $EncryptData=$hardware1&"//"&$Expiry_Date2 MsgBox($MB_SYSTEMMODAL, 'Data to be Encrypte is -', $EncryptData) Global $Encrypted = StringEncrypt($EncryptData, $EncryptionPassword) MsgBox($MB_SYSTEMMODAL, 'Generated Key is -', $Encrypted) DirRemove($CustomerID) DirCreate($CustomerID) FileDelete($CustomerID) FileWrite($CustomerID&"\"&$CustomerID&".ct83",$Encrypted) Func StringEncrypt($sData, $sPassword) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = '' $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_AES_256) _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc ;==>StringEncrypt this is the first part of the code which helps me(developer) to create encrypted files which contain the hardware id and the expiry date of the software the second part is used to run on the client pc to check if the computer has the hardware id that i have registered and created the files for expandcollapse popup#include <Crypt.au3> #include <date.au3> #include <MsgBoxConstants.au3> #include <APIDiagConstants.au3> #include <WinAPIDiag.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $Decrypted Global $Decrypted_Config Global $CustomerID=InputBox("Enter the Customer ID", "Enter the Customer ID Validate the Key ", "", "",- 1, -1) If Not _FileReadToArray($CustomerID&"\"&$CustomerID&".ct83", $Decrypted_Config, 0) Then MsgBox($MB_SYSTEMMODAL, "", "There was an error Reading the 'CustomerID Configuration File'! Please Try again! Using the CustomerID supplied to you") EndIf Global $Decrypted_1 = _ArrayToString($Decrypted_Config) $Encrypted=$Decrypted_1 Global $Decrypted = StringEncrypt(False, $Encrypted,'cybertech83') ; Display the decrypted text. MsgBox($MB_SYSTEMMODAL, '', $Decrypted) Func StringEncrypt($bEncrypt, $sData, $sPassword) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = '' If $bEncrypt Then ; If the flag is set to True then encrypt, otherwise decrypt. $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_AES_256) Else $sReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_AES_256)) EndIf _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc ;==>StringEncrypt CheckExpiry() Func CheckExpiry() Global $Decrypted_Var2 = StringSplit($Decrypted, '//', $STR_ENTIRESPLIT) Global $HardwareID2= $Decrypted_Var2[1] Global $Expiry_Date= $Decrypted_Var2[2] Global $Decrypted_Var23 = StringSplit($Expiry_Date, '/', $STR_ENTIRESPLIT) Global $year= Number($Decrypted_Var23[1]) Global $month= Number($Decrypted_Var23[2]) Global $day= Number($Decrypted_Var23[3]) MsgBox(0,"Expiry Date","The Expiry Date is "&$day&"/"&$month&"/"&$year) $expdate = Floor(_DateToDayValue($year,$month,$day)) If (Floor(_DateToDayValue(@YEAR, @MON, @MDAY)) > $expdate) Then MsgBox(0, "Error", "License has expired") Exit Else MsgBox(0,"Success!","This is a licensed Copy") EndIf EndFunc CheckHardwareID() Func CheckHardwareID() $hardware_Current = _WinAPI_UniqueHardwareID($UHID_All) & @CRLF Global $HardwareID_Config FileWrite("HardwareID.txt",$hardware_Current) If Not _FileReadToArray("HardwareID.txt", $HardwareID_Config, 0) Then MsgBox($MB_SYSTEMMODAL, "", "There was an error Reading the 'CustomerID Configuration File'! Please Try again! Using the CustomerID supplied to you") EndIf Global $hardware_Current = _ArrayToString($HardwareID_Config) Global $HardwareID2= $Decrypted_Var2[1] MsgBox(0,"",$HardwareID2) MsgBox(0,"",$hardware_Current) ;~ #cs if not ($hardware_Current=$HardwareID2) then ;~ If $hardware_Current=$HardwareID2 Then MsgBox(0,"","License is Not Approved for this Machine") Else MsgBox(0,"","License is Approved for this Machine") EndIf EndFunc ;~ #ce Sorry if the the language is too jumbly bt i guess the code is pretty simple and clear. Pls help #noob here\ PS. in short this is something similar to a stackoverflow thread http://stackoverflow.com/questions/25387378/autoit-if-string-not-equal-doesnt-work-the-way-i-expect still i fail to solve the problem Edited April 28, 2016 by CT83 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2016 Moderators Share Posted April 28, 2016 CT83, When apparently identical strings fail to match it is usually because a non-printing character has appeared in one of them. Try looking at the binary of the 2 strings using StringToBinary and see if you can spot a difference. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CT83 Posted April 28, 2016 Author Share Posted April 28, 2016 (edited) 4 minutes ago, Melba23 said: CT83, When apparently identical strings fail to match it is usually because a non-printing character has appeared in one of them. Try looking at the binary of the 2 strings using StringToBinary and see if you can spot a difference. M23 hm... well the strings dont contain any non printable characters according to me they are as follows string 1= {AB17F0E6-ED0A-F61A-33CB-0E10649BE95F} string 2= {AB17F0E6-ED0A-F61A-33CB-0E10649BE95F} n yes i am taking a look at the binaries thnx for the reply edit- after taking a look at the binaries i see that the binaries dont match...! what maybe the reason for this? Edited April 28, 2016 by CT83 Link to comment Share on other sites More sharing options...
AutoBert Posted April 28, 2016 Share Posted April 28, 2016 Using StringStripCR with flag 8 for both strings will help. Also it's only the string from file which have the white space(s) (i think a @CRLF at the end?). Link to comment Share on other sites More sharing options...
CT83 Posted April 28, 2016 Author Share Posted April 28, 2016 Hey!!..thnx a lot guys!.. That un necessary @crlf in the end was the problem... Thnx !!!! Link to comment Share on other sites More sharing options...
AutoBert Posted April 28, 2016 Share Posted April 28, 2016 1 hour ago, CT83 said: That un necessary @crlf in the end was the problem Yes "ABC"&@CRLF <> "ABC". CT83 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now