PDA

View Full Version : Function: Password Maker



smithsps
03-17-2008, 11:17 AM
I made a password maker function for people making new accounts
and such.
I plan on continuing this with a account maker. :spot:

If you plan on using this Plus Rep ++ please.
function PassMaker(lengthofpass: integer): string;
var
chars, pass, passpart : string;
B, passnum : integer;
begin
chars := 'abcd efgh ijk lmnopqrs tuvwxyz123 45678 90';
passnum := 0;
repeat
passnum := passnum + 1;
B := random(42) + 1;
passpart := copy(chars, B, 1);
insert(passpart, pass, passnum);
until(passnum = lengthofpass);
result := pass;
end;

Sample Script: Just spits out passwords according to the length you set it.
program Passmaker;

function PassMaker(lengthofpass: integer): string;
var
chars, pass, passpart : string;
B, passnum : integer;
begin
chars := 'abcd efgh ijk lmnopqrs tuvwxyz123 45678 90';
passnum := 0;
repeat
passnum := passnum + 1;
B := random(42) + 1;
passpart := copy(chars, B, 1);
insert(passpart, pass, passnum);
until(passnum = lengthofpass);
result := pass;
end;

begin
cleardebug;
writeln(PassMaker(8));
end.

Narcle
03-17-2008, 11:32 AM
There is a easier way:
Function PassMaker(Len:integer):string;
var
I:integer;
Cha:string;
begin
Cha := 'abcdefghijklmnopqrstvuwxyz0123456789';
for I := 1 to Len do
result := result + Cha[random(Length(cha))+1];
end;

Didn't want to brag, okay maybe a little. But there is faster and shorter ways for randomizing strings. I've used this quite a bit.

Check out my Name Generator too.

bullzeye95
03-17-2008, 11:43 AM
It can get even shorter than that...
function MakePassword(Length: Integer): String;
var
I: Integer;
begin
for I:= 1 to Length do
Result:= Result + String('abcdefghijklmnopqrstvuwxyz0123456789')[Random(36) + 1];
end; :)

n3ss3s
03-17-2008, 01:16 PM
You both got pwned by a junior member... Like I got yesterday...

I think it was Mixter - the function was something like this:


Function Password(Len: Integer): String;

Begin
While Length(Result) < Len Do
Result := Result + Chr(65 + Random(26));
End;


Even it calls length every round, I think that's a nice "invention" for a jr member... though I don't know did he make it himself, but anyways...


Narcle: You have the wrong idea about bragging :p

GoF
03-17-2008, 01:21 PM
Function Password(Len: Integer): String;

Begin
While Length(Result) < Len Do
Result := Result + Chr(65 + Random(26));
End;


I was thinking of making something like that and posting here, but the good ol' laziness struck me again and I just decided to be useless as always.

Narcle
03-17-2008, 05:32 PM
You both got pwned by a junior member... Like I got yesterday...

I think it was Mixter - the function was something like this:


Function Password(Len: Integer): String;

Begin
While Length(Result) < Len Do
Result := Result + Chr(65 + Random(26));
End;


Even it calls length every round, I think that's a nice "invention" for a jr member... though I don't know did he make it himself, but anyways...


Narcle: You have the wrong idea about bragging :p

Ha I like it.
Bragging... ha hardly. It was just to ease the suffering.

"You both got pwned by a junior member... Like I got yesterday..." Indeed.

Does the While really repeat for that? Looks ominous but if it works... thats all that matters.

Oh and "Length(Result) < Len" so the password is always Len-1 long?

P1nky
03-17-2008, 06:47 PM
so it will tell you the p.w in your debug?

ShowerThoughts
03-17-2008, 07:09 PM
nope..., add writln(result);
maybe inttostr needed to...

n3ss3s
03-17-2008, 07:17 PM
: String;

-.- @ Hermpie...


Oh and "Length(Result) < Len" so the password is always Len-1 long?

Consider again - if it was " <= " it would make it one letter longer ;)

bullzeye95
03-17-2008, 07:38 PM
You both got pwned by a junior member... Like I got yesterday...

I think it was Mixter - the function was something like this:


Function Password(Len: Integer): String;

Begin
While Length(Result) < Len Do
Result := Result + Chr(65 + Random(26));
End;


Even it calls length every round, I think that's a nice "invention" for a jr member... though I don't know did he make it himself, but anyways...


Narcle: You have the wrong idea about bragging :p

I would have done something like how he did the result, but it can't do numbers... I didn't think of the while loop though, that was smart :)

mixster
03-17-2008, 07:58 PM
People always forget the 's' :(
I could've made it do numbers (like Bullzeye did with the String('abcetc.') but having a whole string there makes it not look as cool :p