Delphi dasturlash tilida tasodifiy parollar generatorini tuzish yo'llari
Bugun siz bilan Delphi dasturlash tilida tasodifiy parollar generatorini
tuzishni ko’rib chiqamiz.
Endi Ikkita Button
va bitta Label qo’yib olamiz. Bular bizga protseduralarni ishga tushirish va
tasodifiy parollarni chiqarish uchun kerak bo’ladi.
Bizda bosh class
mavjud o’shani ichida public maydonida ikkita funksiya hosil qilamiz.
Bular :
function
RandomPassword(PLen: Integer): string;
function
RandomWord(dictSize, lngStepSize, wordLen, minWordLen: Integer): string;
endi bu
funksiyalarni hosil qilish uchun ularni ustiga sichqonchani olib borib,
Shift+Ctrl+C
tugmalarini bosing. O’shanda dastur kodida tepadagi funksiyalar hosil bo’ladi va
ularni ichiga yozishimiz mumkin bo’ladi.
Sizga dasturni
barcha kodini keltiraman :
//**********************************************************************
unit Unit1;
interface
uses
Windows,
Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
type
TForm1 =
class(TForm)
Button1:
TButton;
Label1:
TLabel;
Button2:
TButton;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
private
{ Private
declarations }
public
{ Public
declarations }
//Bizga
kerakli funksiyalarni e'lon qilamiz
function
RandomPassword(PLen: Integer): string;
function
RandomWord(dictSize, lngStepSize, wordLen, minWordLen: Integer):string;
//Funksiya
nomlarini o’zingiz hoxlagancha nomlashingiz mumkin.
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
//Label1 ni
Caption xususiyatiga tasodifiy parollarni chiqaramiz
Label1.Caption
:= RandomPassword(10);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//Form1 ni
Caption xususiyatiga tasodifiy parollani chiqaramiz
Caption :=
RandomWord(33, 54, Random(12), 2);
end;
function TForm1.RandomPassword(PLen: Integer): string;
var
str: string;
//harflar joylashishi uchun
begin
Randomize; //
Tasodifiy sonlar generatsiyasini ishga tushirish
//Quyidagi
kiritilgan harflardan foydalanib parol hosil qilamiz
str :=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
Result := '';
repeat
Result := Result + str[Random(Length(str)) +
1];
until
(Length(Result) = PLen)
end;
function TForm1.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;
end.
//**********************************************************************
Ishlatish endi
sizga, agar bu dasturga qo’shimchalar qilishni hoxlasangiz, izoh qoldiring!
Funksiyalarga
tushunmagan bo’lsangiz, izoh qoldiring!
Eng avvalo
tushunishga harakat qiling!
Savollaringiz
bo’lsa izoh berish joyida qoldiring!
Birgalashib ishlaymiz!
Comments
Post a Comment
Iltimos, fikrlaringizni yozib qoldiring !