whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

20 Visitors Online


 
...generate a random password?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Print tip ]  

Tip Rating (43):  
     


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

procedure TForm1.Button1Click(Sender: TObject);
begin
  
//generate a password with 10 chars
  
label1.Caption := RandomPassword(10);
end;


// Another function from ReNoiZer /=RNZ=/; renoizer@mail.ru

function RandomWord(dictSize, lngStepSize, wordLen, minWordLen: Integer): string;
begin
  
Result := '';
  if (wordLen < minWordLen) and (minWordLen > 0) then
    
wordLen := minWordLen
  else if (wordLen < 1) and (minWordLen < 1) then wordLen := 1;
  repeat
    
Result := Result + Chr(Random(dictSize) + lngStepSize);
  until (Length(Result) = wordLen);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  
//generate a password with 10 chars
  
Caption := RandomWord(33, 54, Random(12), 2);
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners