Ver Mensaje Individual
  #43  
Antiguo 28-03-2007
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 19.437
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Segun lo que hemos comentado, cambiando un poco la función y añadiendo un parámetro, puedes obtener el número "a trozos".
Revisa este ejemplo.

La de obtener el serial quedaría así:

Código Delphi [-]
function GiveSerial(ABase: Integer; AUserName: string; APart:Integer): string;
const
  RsError = 'Error en los parámetros.';
var
  A: Integer;
begin
  if (ABase <> 0) and (AUserName <> '') then
  begin
    if (APart = 1) then begin
      A := ABase * Length(AUserName) + Ord(AUserName[1]) * 666;
      Result := IntToStr(A);
      Exit;
    end;

    if (APart = 2) then begin
      A := ABase * Ord(AUserName[1]) * 123;
      Result := IntToStr(A);
      Exit;
    end;

    if (APart = 3) then begin
      A := ABase + (Length(AUserName) * Ord(AUserName[1])) * 6613;
      Result := IntToStr(A);
      Exit;
    end;
  end
  else
    Result := RsError;
end;

Y en este caso cambiaríamos la de comprobación por algo así:

Código Delphi [-]
var
  Str, Str2: String;
  i, l1, l2:Integer;
  j1, j2, j3, j4:Integer;
begin

  Str := GiveSerial(123456, Edit1.Text, 1);
  Str2 := Copy(Edit2.Text, 1, Length(Str));

  if (Str <> Str2) then begin
    MessageDlg('SN incorrecto.', mtError, [mbOK], 0);
    Exit;
  end;

  l1 := Length(Str);
  Str := GiveSerial(123456, Edit1.Text, 2);
  Str2 := Copy(Edit2.Text, l1 + 2, Length(Str));

  if ((StrToIntDef(Str, 0) - StrToIntDef(Str2, -99)) <> 0) then begin
    MessageDlg('SN incorrecto.', mtError, [mbOK], 0);
    Exit;
  end;

  l2 := Length(Str);
  Str := GiveSerial(123456, Edit1.Text, 3);
  Str2 := Copy(Edit2.Text, l1 + l2 + 3, Length(Str));

  j1 := StrToIntDef(Str, 0);
  j2 := StrToIntDef(Str2, -99);
  j3 := (j1 DIV j2);
  j4 := (j1 MOD j2);
  if (j3 <> 1) or (j4 <> 0)then begin
    MessageDlg('SN incorrecto.', mtError, [mbOK], 0);
    Exit;
  end;


  MessageDlg('El programa se ha registrado correctamente.', mtInformation, [mbOK], 0);

end;

Es un ejemplo, pero fácilmente puedes generarlizarla un poco más... (lo he escrito sobre la macha y tampoco lo he pensado mucho...).
El número de serie no aparece completo, es más ni siquiera aparecen todos los trozos. Sinceramente creo que es casi imposible que alguien mirando la memoria del programa se le ocurre que 6 números que hay por ahí son parte del número de serie. Si la comprobación la cambias de orden pues mucho menos.

Otro tema es el del Debug; Eso si quieres lo dejamos para otro momento....
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.

Última edición por Neftali [Germán.Estévez] fecha: 28-03-2007 a las 19:09:12.
Responder Con Cita