Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: DorkeyDear on September 17, 2008, 03:50:02 pm
-
Function Name: MD5
Script Description: Basically sense I had issues using MD5String before, this tries to get a correct value out of it
Original Author: Curt (DorkeyDear)
Core Version: 2.2 (Server v2.6.3)
Code:
function MD5(const Str: string): string;
var
 i: byte;
begin
 while (true) do begin
  Result := MD5String(Str);
  for i := 0 to 11 do begin
   if (Result <> MD5String(Str)) then begin
    i := 0;
    break;
   end;
  end;
  if (i > 0) then break;
 end;
end;
-
hmm?
while (true) do begin
  Result := MD5String(Str);
  for i := 0 to 11 do begin
   if (Result <> MD5String(Str)) then begin
.........
You already give "Result := MD5String(Str)",so "if (Result <> MD5String(Str))"Â will never happen right?
And then if this is what you want then
for i := 0 to 11 do begin
   if (Result <> MD5String(Str)) then begin
    i := 0;
    break;
The "i" will always 0. Is it a always loop code?
-
He's doing this because evidently MD5String doesn't always respond with the same info... could be wrong though (correct me please).
-
iDante is correct, i had issues with it before, so I created this
It does 12 checks, if any of them are different than the first set value of it, it will reset the return value and start the checks over
I probably could have made it with repeat until statement to make it slightly shorter, but it doesn't matter that much.
function MD5(const Str: string): string;
var
 i: byte;
begin
 repeat
  Result := MD5String(Str);
  for i := 0 to 11 do begin
   if (Result <> MD5String(Str)) then begin
    i := 0;
    break;
   end;
  end;
 until (i > 0);
end;
but untested, don't use repeat statement often, could be wrong
actually this may also work with a while (i > 0) sense i starts at 0, but wouldn't in other languages that don't initially set the value of numbers..
-
while not regexpmatch('^[0-9a-f]{32}$',result) do
result := md5string(str);
-
while not regexpmatch('^[0-9a-f]{32}$',result) do
 result := md5string(str);
Nice thinking, didnt even think about that... although wouldn't it be possible for the "random" error to modify one of the 32 characters to be an invalid allowed character?
but then again i guess mine isn't perfect.. if x amount of the same error occurs in a row :P then it'll recognize it as correct, heh.
-
but then again i guess mine isn't perfect.. if x amount of the same error occurs in a row :P then it'll recognize it as correct, heh.
yup, you can never be sure about that. Also it seems to be rare enough to be cared about.
And the while loop with a regex can hang your server if the error occurs too much, but it'd already mean that something is really wrong with the server so it doesnt matter either ;)
-
yeah ive had problems with md5string adding extra letters or only coming back with just half the encryption before