PDA

View Full Version : Simple Delphi application - to generate passwords



Dumzaz
03-08-2007, 02:18 PM
Hi all I need to develop a simple Delphi app - that generates passwords. Each password must be six characters long - selected randomly - and it must be alpha-numeric. Here is what I have so far. I am using an array to store the alphabets. If i can get the simple version to work, i will extend it.

Problem with mine is that it does not concatenate the string - it only returns one character

begin
Randomize;
Password := '';
for nCounter := 1 to 5 do;
begin
nIndex := Random(5) + 1;
Password := Password + Alphabets[nIndex];
end;
edtShowPassWord.Text := Password;
end;

Scooby_Doo
03-08-2007, 02:34 PM
Since you can treat a string var as an array try

Password[ncount] := Alphabets[nIndex];

Conspirator
03-08-2007, 09:58 PM
Your random function is all wrong and the randomize must be in form.create not the button code.

//CODE: Produces Upper&Lower case and 0-9 pwds
var Password:String;
Picked,Count:integer;
begin
//Dumzaz's homework
Password:='';
For Count:=1 to 6 do
begin
Picked:=Random(62);
Case Picked of
0..9:Password:=Password+inttostr(picked);
10..35:Password:=Password+chr(Picked-10+65);
36..61:Password:=Password+chr(Picked-36+97);
end;
end;
Showmessage(Password);
end;

Dumzaz
07-08-2007, 11:38 AM
Thanks, I see I was going about the wrongway altogether. It works. It seems i need to understand how to use this function

function Chr(X: Byte): Char;

Description
Chr returns the character with the ordinal value (ASCII value) of the byte-type expression, X.

Thanks