تبليغاتX
مرکز تخصصی دلفی - ایجاد یک پسورد به صورت خدکار(Random String)

مرکز تخصصی دلفی

این وبلاگ توسط کم سن ترین برنامه نویس ایران مدیریت می «شد»

ایجاد یک پسورد به صورت خدکار(Random String)

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

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

 

function RandomWord(dictSize, lngStepSize, wordLen, minWordLen: Integer): string;
begin//delphi-center.blogfa.com
  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//delphi-center.blogfa.com
  //generate a password with 10 chars
  Caption := RandomWord(33, 54, Random(12), 2);
end;

+ نوشته شده در  دوشنبه شانزدهم مرداد 1385ساعت 16:39  توسط کوشا نخعی  |