[DUG] Problem converting this
Stefan Mueller
muellers at orcl-toolbox.com
Mon Mar 27 11:42:57 NZDT 2017
2 ways to solve:
- convert to utf8string and hash that one. Most old ansi-hashes will match the md5 of utf8 (unless they contain special characters, like umlauts and other diacritics).
- check if your password contains Unicode (if ansistring(pw)<>pw then … ) and depending on that one use the right GetMD5 call (if not use ansi, if yes use widestring). This workaround will deal with umlauts and other diacritics correctly.
Ps: GetMD5(@pc[0], 1+lp+16); should be GetMD5(@pc[0], 1+lp*2+16); for Unicode strings!
Kind regards,
Stefan Müller,
R&D Manager
ORCL Toolbox Ltd.
Auckland, New Zealand
P Please consider the environment before printing this email
This message is intended for the adresse named above and may contain privileged or confidential information.
If you are not the intended recipient of this message you must not use, copy, distribute or disclose it to anyone.
From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Jolyon Direnko-Smith
Sent: Monday, 27 March 2017 11:15 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Problem converting this
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 <jscoulter at gmail.com> 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: delphi at listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at listserver.123.net.nz with Subject: unsubscribe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20170327/c335b174/attachment-0001.html
More information about the Delphi
mailing list