Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Generator
#1
As I see in my other thread You cant really make a keylogger. But I was wondering how would I start making a password generator....

1) Get a bunch of characters and digits.

2) From that try to output a random password in a 7 digit or a user defined number.

Help Would be great..
Reply
#2
Here's a little program that can get you started. I tested it.

It allows numeric characters, uppercase alphabetics between A-Z and lowercase alphabetics between a-z. If you don't want both upper and lower, you can just remove the corresponding FOR loop.

The resultant password is generated purely at random, with no restrictions such as repeated characters, or any other password rules like requiring mixed alpha and numeric characters.
Code:
rem Generate a random password.
defint a-z
RANDOMIZE TIMER
dim t (1 to 62)     '10 numerics + 26 uppercase + 26 lowercase
tmax=0              'last table element used

for x = 48 to 57    'store numeric ASCII character codes
    tmax=tmax+1
    t(tmax)=x
next x

for x = 65 to 90    'store uppercase ASCII character codes (optional)
    tmax=tmax+1
    t(tmax)=x
next x

for x = 97 to 122   'store lowercase ASCII character codes (optional)
    tmax=tmax+1
    t(tmax)=x
next x

print "Enter length of password desired (max=20) ";
input plen
if plen<1 or plen>20 then print "Invalid length":system

pw$=""
randlower=1
randupper=tmax
for x = 1 to plen
   rand = int(RND * (randupper - randlower + 1)) + randlower
   pw$=pw$+chr$(t(rand))
next x
print "The random password is ";pw$
system
*****
Reply
#3
How would I get the password that is generated and put it in a saved file?

I tried using the OPEN, WRITE, and CLOSE functions but couldnt get it right!!
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Reply
#4
Code:
input "Save as: ",sf$
open sf$ for output as #1
write #1, pw$
close #1
Reply
#5
Hey thanks Speedlemon. I would just like to get one thing..
I dont understand this part of the code clearly and how it randomly generates passwords. Someone please care to explain!!

Code:
pw$=""
randlower=1
randupper=tmax
for x = 1 to plen
   rand = int(RND * (randupper - randlower + 1)) + randlower
   pw$=pw$+chr$(t(rand))
next x
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Reply
#6
Well, as you know, pw is the password. First of all, the for statement...

Code:
for x = 1 to plen
This is saying, "Do the following, plen times". Then the next line...
Code:
rand = int(RND * (randupper - randlower + 1)) + randlower
This generates a random number between randlower and randupper, then stores it in rand. The next line...
Code:
pw$=pw$+chr$(t(rand))
is the tricky part. CHR$ is a function in Qbasic that returns the character with the proper code. The array, t, was defined earlier in the program, and has all of the upper and lowercase letters in the alphabet. So the value at t(rand) is a random letter from A-Z and a-z. It then adds this letter to the end of pw.

In total, it does this plen times, ending up with a random string.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#7
@Torahteen: Very good explanation.

@Hybr!d: If the code is still not clear, I'll walk it through a little slower and more detail for you, if you like.
*****
Reply
#8
Thanks for the explanation Torahteen. Moneo no need for further explanation I get it now...

I am starting to get qbasic now!!
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Reply
#9
Hey guys how would I use like one variable to define all the characters I can use? Like this

Code:
CONST Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", NChars = 62

It would be alot easier then all that code at the top of the program...
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Reply
#10
Quote:Hey guys how would I use like one variable to define all the characters I can use? Like this
Code:
CONST Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", NChars = 62
It would be alot easier then all that code at the top of the program...
"all that code at the top" was intended so you could choose whether to include either or both uppercase and lowercase characters, which you did not specify in your original requirements. You just said "a bunch of characters and digits".

If you always will use all the characters that you now mention, yes, the code can be simplified, as follows:
Code:
rem Generate a random password.
defint a-z
RANDOMIZE TIMER

Chars$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
NChars=len(Chars)  'This allows later add or delete of characters

dim t (1 to NChars)

rem Store ASCII code of each char into consecutive locations of t().
for x = 1 to NChars
     t(x)=asc(mid$(Chars$,x,1))
next x

print "Enter length of password desired (max=20) ";
input plen
if plen<1 or plen>20 then print "Invalid length":system

pw$=""
randlower=1
randupper=NChars
for x = 1 to plen
   rand = int(RND * (randupper - randlower + 1)) + randlower
   pw$=pw$+chr$(t(rand))
next x
print "The random password is ";pw$
system
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)