# VBForums CodeBank > CodeBank - Other >  [DELPHI] - Generate Random Password

## Madboy

```
function RandomPassword(PLen: Integer): string;
var
  str: string;
begin
  Randomize;
  str    := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  Result := '';
  repeat
    Result := Result + str[Random(Length(str)) + 1];
  until (Length(Result) = PLen)
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := RandomPassword(10);
end;
```

----------

