Thanks Jolyon! works a treat now.....glad to not be stuck with Delphi 2007 for this solution !! :-)
Thanks, Jeremy On Mon, Mar 27, 2017 at 11:14 AM, Jolyon Direnko-Smith <[email protected] > wrote: > There is nothing that immediately jumps out as suspicious in the code, > other than the call into OverByteICS code (which is not shown and so cannot > be verified). > > If the problem is that for any given input you are now getting a different > MD5 than you did previously, then the problem may simply be that when you > has a UnicodeString version of what was previously an ANSIString, then your > hash will be different due to the fact simply that the two strings *are > in fact different*. > > Hello#0 > vs H#0e#0l#0l#0o#0#0#0 > > > i.e. the code is perfectly valid for hashing an ANSIString in a Delphi > version where String == ANSIString, and yet is also perfectly valid for > hashing a UnicodeString in versions where String == UnicodeString. > > But you will get a different result in each case simply because ANSIString > <> UnicodeString. > > > If that is the case, and you want/need to ensure you are still hashing an > ANSIString in Delphi 2010+ then you will need to convert the > (Unicode)String to an ANSIString before hashing it. > > - change all your string/char types in the function to > ANSIString/ANSIChar > - convert the input strings to ANSI > - process them as ANSI > - ensure you are using the correct ANSI implementation of OverByte (or > possibly look at switching to System.Hash) > - convert your results back from ANSI to UnicodeString when done (if > necessary/appropriate) > > > hth > > On 27 March 2017 at 08:32, Jeremy Coulter <[email protected]> wrote: > >> Hi all. It might be I have been mucking around with this too much and >> have just simply got confused! >> >> I am converting some code from Delphi 2007 to 10.1. >> I am having an issue on D 10.1 with this code which is fin under 2007 and >> it will be due to the unicode stuff that was introduced. >> Can someone let me know how I would convert this to be 10.1 compatible? I >> have spent some time on it and not really got any where. >> >> Thanks, Jeremy >> >> function encode_password(passw, hash: string): string; >> var >> ac, temp: string; >> pc: array of char; >> i, lp: integer; >> begin >> if (hash<>'') and (passw<>'') >> then begin >> lp:=length(passw); >> setlength(pc,1+lp+16); >> pc[0]:=#0; >> move(passw[1],pc[1],lp); >> for i:=0 to 15 >> do begin >> ac:=copy(hash,i*2+1,2); >> if ac<>'' >> then pc[1+lp+i]:=Chr(StrToInt('$' + ac)); >> end; >> temp:=GetMD5(@pc[0], 1+lp+16); //GETMD5 is in the OverByteICS >> code so should be ok >> end >> else begin >> temp:='#error#'; >> end; >> result:=lowercase(temp); >> end; >> >> _______________________________________________ >> NZ Borland Developers Group - Delphi mailing list >> Post: [email protected] >> Admin: http://delphi.org.nz/mailman/listinfo/delphi >> Unsubscribe: send an email to [email protected] with >> Subject: unsubscribe >> > > > _______________________________________________ > NZ Borland Developers Group - Delphi mailing list > Post: [email protected] > Admin: http://delphi.org.nz/mailman/listinfo/delphi > Unsubscribe: send an email to [email protected] with > Subject: unsubscribe >
_______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: [email protected] Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to [email protected] with Subject: unsubscribe
