unit uPasswordUtils;

interface

function EncriptarPassword(const password : string): String;
function EncriptarPasswordOSC(const password : string): String;
implementation

uses
  MD5, SysUtils;

function EncriptarPassword(const password : string): String;
var
  t : TMD5Digest;
  pass_encriptada : String;
begin
  t := MD5String(password);
  pass_encriptada := MD5DigestToStr(t);
  Result := LowerCase(pass_encriptada);
end;

function EncriptarPasswordOSC(const password : string): String;
var
  t : TMD5Digest;
  salt : String;
  pass_encriptada : String;
  i : integer;
begin
//    for ($i=0; $i<10; $i++) {
//      $password .= tep_rand();
//    }
//
//    $salt = substr(md5($password), 0, 2);
//
//    $password = md5($salt . $plain) . ':' . $salt;

  pass_encriptada := '';
  Randomize;
  for I := 0 to 9 do
    pass_encriptada := pass_encriptada + FloatToStr(Random(10000000000));

  t := MD5String(password);
  salt := Copy(MD5DigestToStr(t), 0, 2);

  t := MD5String(salt + password);
  pass_encriptada := MD5DigestToStr(t);
  Result := LowerCase(pass_encriptada) + ':' + salt;
end;


end.
