unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, math, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Buttons, ComCtrls, Menus;

type

  { TForm1 }

  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    Memo1: TMemo;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    RadioGroup1: TRadioGroup;
    SaveDialog1: TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);

  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  clave: string;

implementation

{$R *.lfm}

{ TForm1 }

function altaSeguridad():string;
var
 letras : array[1..63] of char;
 i : integer;

begin
 clave :='';
 randomize;
 for i:=1 to 63 do   { * 63 caracteres * }
  begin
    letras[i] := chr(32+random(94));  { * ASCII 32 - 126 * }
    clave := clave + letras[i];
  end;
end;

function bajaSeguridad():string;
var
 letras : array[1..20] of char;
 i : integer;

begin
 clave :='';
  randomize;
 for i:=1 to 20 do { * 20 caracteres * }
  begin
    letras[i] := chr(32+random(94));  { * ASCII 32 - 126 * }
    clave := clave + letras[i];
  end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
    RadioGroup1.ItemIndex := 1 ;
end;



procedure TForm1.MenuItem1Click(Sender: TObject);
begin
  {radiobutton1.setChecked(true);}

  If RadioGroup1.ItemIndex = 0 then  bajaSeguridad();
  If RadioGroup1.ItemIndex = 1 then  altaSeguridad();
  Memo1.Lines.text:= clave;
end;

procedure TForm1.MenuItem2Click(Sender: TObject);
begin
  Memo1.SelectAll;
  Memo1.CopyToClipboard;
  ShowMessage('Copiado al portapapeles con éxito');
end;

procedure TForm1.MenuItem3Click(Sender: TObject);
begin
 savedialog1.execute;
 Memo1.lines.savetofile(savedialog1.filename);
end;

end.

