Posts: 33
Threads: 8
Joined: Jan 2006
Hey guys. I got most of this code from this forum from last time I asked and this time I wanted to edit it so It suits my thoughts. For like users choosing there own characterset they want to use in making a password this is what I came up with.. Hopefully someone can tell me where my problem is
Code:
REM Generate a random password.
START:
PRINT "Password Generator 1.0"
PRINT
PRINT "Charactersets available"
PRINT
PRINT "1) abcdefghijklmnopqrstuvwxyz "
PRINT
PRINT "2) ABCDEFGHIJKLMNOPQRSTUVWXYZ "
PRINT
PRINT "3) 0123456789!?><+_-*&^%$#@,./][\"
PRINT
PRINT "4) ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?><+_-*&^%$#@,./][\ "
INPUT "Input your characterset"; selection
IF selection = 1 THEN
characterset = "abcdefghijklmnopqrstuvwxyz"
GOTO PROGRAM
ELSE IF selection = 2 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
GOTO PROGRAM
ELSE IF selection = 3 THEN
characterset = "0123456789!?><+_-*&^%$#@,./][\"
GOTO PROGRAM
ELSE IF selection = 4 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?><+_-*&^%$#@,./][\"
GOTO PROGRAM
ELSE
PRINT "Invalid Selection"
GOTO START
END IF
PROGRAM:
CLS
DEFINT A-Z
RANDOMIZE TIMER
Chars$ = "characterset"
NChars = LEN(Chars$)'This allows later add or delete of characters
PRINT "Enter length of password desired (max=36) ";
INPUT plen
IF plen < 1 OR plen > 36 THEN PRINT "Invalid length": SYSTEM
pw$ = ""
randlower = 1
randupper = NChars
FOR x = 1 TO plen
rand = INT(RND * (randupper - randlower + 1)) + randlower
pw$ = pw$ + MID$(Chars$, rand, 1)'Pickup a char from random position in Chars$
NEXT x
PRINT "The random password is "; pw$
INPUT "Save as: ", sf$
OPEN sf$ FOR OUTPUT AS #1
WRITE #1, pw$
CLOSE #1
SYSTEM
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 421
Threads: 22
Joined: Oct 2005
Don't DEFINT A-Z and RANDOMIZE TIMER need to be at the beginning of the program?
In the beginning, there is darkness â the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Posts: 33
Threads: 8
Joined: Jan 2006
There is onething I dont understand in code which is.. EXIT DO.. What does this mean there are so many DO statements in code I dont know where it ends up going. Can somone please explain it. Also thanks for that cha0s It works now.. Thanks alot im going to do some minor work on it thanks man. Ill post up finished result
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 33
Threads: 8
Joined: Jan 2006
For some reason I wanted to make like a selection for user to specify if he wants to save file or not.. And for some reason it keeps printing redo from start.. This is the code hopefully someone can help me..
Code:
REM Generate a random password.
DEFINT A-Z
RANDOMIZE TIMER
START:
'' before you had it as a single.
DIM characterset AS STRING
DO
CLS
PRINT "Password Generator 1.0"
PRINT
PRINT "Charactersets available"
PRINT
PRINT "1) abcdefghijklmnopqrstuvwxyz "
PRINT
PRINT "2) ABCDEFGHIJKLMNOPQRSTUVWXYZ "
PRINT
PRINT "3) 0123456789!?><+_-*&^%$#@,./][\"
PRINT
PRINT "4) ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?><+_-*&^%$#@,./][\ "
PRINT
PRINT
INPUT "Input your characterset"; selection
IF selection = 1 THEN
characterset = "abcdefghijklmnopqrstuvwxyz"
EXIT DO
ELSEIF selection = 2 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
EXIT DO
ELSEIF selection = 3 THEN
characterset = "0123456789!?><+_-*&^%$#@,./][\"
EXIT DO
ELSEIF selection = 4 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?><+_-*&^%$#@,./][\"
EXIT DO
END IF
LOOP
DIM Chars AS STRING
Chars = characterset
NChars = LEN(Chars)'This allows later add or delete of characters
DO
CLS
PRINT "Enter length of password desired (max=36) ";
INPUT plen
IF plen > 0 AND plen < 37 THEN
EXIT DO
END IF
LOOP
DIM pw AS STRING
randlower = 1
randupper = NChars
FOR x = 1 TO plen
rand = INT(RND * randupper) + 1
pw = pw + MID$(Chars, rand, 1)'Pickup a char from random position in Chars$
NEXT x
PRINT "The random password is "; pw
PRINT
PRINT
PASSWORD:
INPUT "Would you like to save password to file? (y/n)", save
SELECT CASE save
CASE y
PRINT
PRINT
INPUT "Save as: ", sf$
OPEN sf$ FOR OUTPUT AS #1
WRITE #1, pw
CLOSE #1
CASE n
GOTO START
CASE ELSE
PRINT "Invalid Selection"
GOTO PASSWORD
END SELECT
SYSTEM
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 33
Threads: 8
Joined: Jan 2006
Oh Thanks man your a champ.. Now I understand it thanks alot
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 33
Threads: 8
Joined: Jan 2006
Here is complete program now. Thanks for all your help guys here is what I put together.
Code:
'This program is designed to generate passwords. Made by Ali Abdulsater and help from qbasicnews.com forum members.
DEFINT A-Z 'This sets the default data types for variables
RANDOMIZE TIMER 'Randomises the Timer
START: 'Anchor point
DIM characterset AS STRING 'This declares characterset as a STRING
DIM selection AS INTEGER 'This declares selection as a INTEGER
DO 'This is going to be sued to repeat a block of statements
CLS ' Clear Screen
PRINT "Password Generator 1.0 by Ali (Hybr!d)"
PRINT
PRINT "Charactersets available"
PRINT
PRINT "1) Lowercase Alphabet "
PRINT
PRINT "2) Uppercase Alphabet "
PRINT
PRINT "3) Numbers and Symbols"
PRINT
PRINT "4) Lowercase/Uppercase/Numbers and Symbols"
PRINT
PRINT "5) Exit Program"
PRINT
INPUT "Input your characterset (1/2/3/4) "; selection
IF selection = 1 THEN
characterset = "abcdefghijklmnopqrstuvwxyz"
EXIT DO
ELSEIF selection = 2 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
EXIT DO
ELSEIF selection = 3 THEN
characterset = "0123456789!?><+_-*&^%$#@,./][\"
EXIT DO
ELSEIF selection = 4 THEN
characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?><+_-*&^%$#@,./][\"
EXIT DO
ELSEIF selection = 5 THEN
SYSTEM 'This is used to close all open files and return to Operating system
ELSE
PRINT "Invalid Selection"
SLEEP 2
GOTO START
END IF
LOOP
DIM Chars AS STRING 'This declares Chars as STRING
Chars = characterset
NChars = LEN(Chars) 'LEN function is used to return number of characters in a string
DO
CLS
PRINT "Enter length of password desired (max=36) ";
INPUT plen
IF plen > 0 AND plen < 37 THEN 'This checks if the length user input is within range
EXIT DO
END IF
LOOP
DIM pw AS STRING 'This declares pw as STRING
randlower = 1
randupper = NChars
FOR x = 1 TO plen
rand = INT(RND * randupper) + 1 'Produces random character
pw = pw + MID$(Chars, rand, 1) 'Pickup a char from random position in Chars$
NEXT x 'Goes for next x till user specified length is done
PRINT "The random password is "; pw
PRINT
PRINT
PASSWORD: 'Anchor point
DIM save AS STRING 'This declares save as STRING
DIM selection1 AS STRING 'This declares selection1 as STRING
INPUT "Would you like to save password to file? (y/n)", save
SELECT CASE save 'Used for user to go alternative paths
CASE "y"
PRINT
PRINT
PRINT "Save in the following manner <filename>.txt"
PRINT
PRINT
INPUT "Save as: ", sf$
OPEN sf$ FOR OUTPUT AS #1
WRITE #1, pw
CLOSE #1
PRINT
PRINT "File saved!!"
PRINT
ANOTHERPASS: 'Anchor Point
CLS
INPUT "Would you like to make another password? (y/n)"; selection1
IF selection1 = "y" THEN
GOTO START
ELSEIF selection1 = "n" THEN
SYSTEM
ELSE
PRINT "Invalid Selection"
SLEEP 1
GOTO ANOTHERPASS
END IF
CASE "n"
GOTO START
CASE ELSE
PRINT "Invalid Selection"
GOTO PASSWORD
END SELECT
SYSTEM
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]