username & Passwored exe

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
System-Psycho

username & Passwored exe

Post by System-Psycho »

Hi,

I know littel qbaisc, and to be honest i dont really want to learn the hole of qbais to make this one littel program.

I am trying to creat a prgram that asks for a username and password.
The code i have at the moment is below;

Code: Select all

CLS
PRINT "Remote Access Server."
PRINT "Admins Only!"
PRINT ""
INPUT "password:", usr$
IF urs$ = "owned" OR usr$ = "happyhacker" OR usr$ = "netstorm" THEN GOTO 1 ELSE GOTO 2

1 PRINT "Welcome"
PRINT "You now have access to or online command prompt shell, uploading file to are ftp or uploading to the website, Our online chat and are exclusive members area"
PRINT " Enjoy System-Psycho"
end

2 PRINT "Access is denine"
The proplem is as follows; i would like ther to be a different thing heppen depending on the username typed but i cant figer this out.
my question is, How would i have something different happen depending on the input?
Thanks sp
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

You could do a simple thing like print the usr$ behind welcome for a personal greeting:

Code: Select all

CLS 
PRINT "Remote Access Server." 
PRINT "Admins Only!" 
PRINT "" 
INPUT "password:", usr$ 
IF urs$ = "owned" OR usr$ = "happyhacker" OR usr$ = "netstorm" THEN GOTO 1 ELSE GOTO 2 

1 PRINT "Welcome"; usr$
PRINT "You now have access to or online command prompt shell, uploading file to are ftp or uploading to the website, Our online chat and are exclusive members area" 
PRINT " Enjoy System-Psycho" 
end 

2 PRINT "Access is denine"
Or maybe use multiple IFs for different domains.. say Owned is the main Admin, and the others Sub-admins:

Code: Select all

CLS 
PRINT "Remote Access Server." 
PRINT "Admins Only!" 
PRINT "" 
INPUT "password:", usr$ 
IF urs$ = "owned" THEN GOTO 1
IF  usr$ = "happyhacker" OR usr$ = "netstorm" THEN GOTO 2
PRINT "Access is denine" 
END

1 PRINT "Welcome to Main Log." 
PRINT "You now have access to or online command prompt shell, uploading file to are ftp or uploading to the website, Our online chat and are exclusive members area" 
PRINT " Enjoy System-Psycho" 
end 

2 PRINT "Welcome to Sub Log"
PRINT "You now have access to our online chat and are exclusive members area" 
PRINT " Enjoy System-Psycho" 
end 
And also a cool tip, use UCASE$() or LCASE$() to make input case-insensitive:

Code: Select all

IF UCASE$(usr$) = "OWNED" THEN ...

Code: Select all

IF LCASE$(usr$) = "owned" THEN ...
NOTE: UCASE$() makes string all caps, and LCASE make it lower case.. So if you input: Owned, OwNeD, or OWNED it would still work by using these converters.. :wink: You only need one of the two tho, I normally just use UCASE$, other might prefer LCASE$.. but the end result is the same as for case-insensitivity
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Select case.

Code: Select all

SELECT CASE usr$
CASE "Netstorm"
(netstorm stuff goes here)
CASE "HappyHackey"
(happyhacker stuff goes here)
CASE "Owned"
(owned stuff goes here)
END SELECT
And, you may want to use UCASE$ and LCASE$ to check the varibles.
Image
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Hi, Nathan... I already told him about UCASE$ and LCASE$... :P

Here's how it goes with that exapmle tho: I preffer IF.. THEN, but this is good too.. :wink:

Code: Select all

CLS 
PRINT "Remote Access Server." 
PRINT "Admins Only!" 
PRINT "" 
INPUT "password:", usr$

SELECT CASE UCASE$(usr$)
CASE "NETSTORM" 
'(netstorm stuff goes here) 
CASE "HAPPYHACKEY" 
'(happyhacker stuff goes here) 
CASE "OWNED" 
'(owned stuff goes here) 
END SELECT
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

...
...
(deleting this word for sake of not being banned)
Image
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

I'm using Rattrapmax6's last posted code as a base.

I'm changing the input prompt from "password" to "Admin Username" because none of the code so far is checking for passwords.

I'm adding CASE ELSE logic to handle the case of an invalid username.

I structured the CASE logic.

Code: Select all

CLS 
PRINT "Remote Access Server." 
PRINT "Admins Only!" 
PRINT "" 
INPUT "Admin Username:", usr$ 

SELECT CASE UCASE$(usr$) 
            CASE "NETSTORM" 
                     '(netstorm stuff goes here) 
            CASE "HAPPYHACKEY" 
                     '(happyhacker stuff goes here) 
            CASE "OWNED" 
                     '(owned stuff goes here) 
            CASE ELSE
                     PRINT "Invalid Username, access denied."
                     SYSTEM
END SELECT
Not a big difference, but a little cleaner and more complete.
*****
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Right.. I sat back and wrote a more simulated Password system, it asks for username, then the password.. and while you type the pasword it displays it as: "******"..

Very nice, and something you can play with, look over, and learn from maybe.. :wink:

Psssys.bas (Made in FreeBasic, Tested in QBasic.. Runs well in both..)

Code: Select all

'Username/Password system by Rattrapmax6(Kevin(x.t.r.GRAPHICS))
' Two test usernames: User1 and Admin
'Passwords: User1 = Enter || Admin = LetMeIn
' System is case-insensitive.. :)

CLS 'Clear screen
PRINT "Welcome!"
PRINT "Enter User:";
DO
    LOCATE 2, 12: PRINT dspl$; "   " 'Display storing varible
    press$ = INKEY$
    IF press$ <> "" THEN 'On press
        'Filter Backspace, subtract varible
        IF press$ = CHR$(8) AND LEN(dspl$) > 0 THEN
            sb = LEN(dspl$)
            Ndspl$ = MID$(dspl$, 1, (sb - 1))
            dspl$ = Ndspl$
        'Filter Enter, Exit for checking
        ELSEIF press$ = CHR$(13) THEN
            EXIT DO
        'Add up user input to varible
        ELSE
            dspl$ = dspl$ + press$
        END IF
    END IF
LOOP

SELECT CASE UCASE$(dspl$)
CASE "USER1"
    PRINT "Enter Pasword:";
    usr$ = dspl$
    dspl$ = ""
    DO
        LOCATE 3, 15: PRINT pss$; "   "' NEW, print the ** for the varible
        press$ = INKEY$
        IF press$ <> "" THEN
            IF press$ = CHR$(8) AND LEN(dspl$) > 0 THEN
                sb = LEN(dspl$)
                Ndspl$ = MID$(dspl$, 1, (sb - 1))
                Npss$ = MID$(pss$, 1, (sb - 1)) 'NEW, Subtract ***
                dspl$ = Ndspl$
                pss$ = Npss$ 'Restore the ***
            ELSEIF press$ = CHR$(13) THEN
                EXIT DO
            ELSE
               dspl$ = dspl$ + press$
               pss$ = pss$ + "*" 'NEW, calculate how many ***
            END IF
        END IF
    LOOP
    IF UCASE$(dspl$) = "ENTER" THEN 
        PRINT "Welcome to our servers, "; usr$; "!"
        PRINT "Press any key to end..."
        SLEEP
        END
    ELSE
        PRINT "Username and password to not compute!"
        PRINT "Press any key do end..."
        SLEEP
        END
    END IF
CASE "ADMIN"
    PRINT "Enter Pasword:";
    usr$ = dspl$
    dspl$ = ""
    DO
        LOCATE 3, 15: PRINT pss$; "   "
        press$ = INKEY$
        IF press$ <> "" THEN
            IF press$ = CHR$(8) AND LEN(dspl$) > 0 THEN
                sb = LEN(dspl$)
                Ndspl$ = MID$(dspl$, 1, (sb - 1))
                Npss$ = MID$(pss$, 1, (sb - 1))
                dspl$ = Ndspl$
                pss$ = Npss$
            ELSEIF press$ = CHR$(13) THEN
                EXIT DO
            ELSE
               dspl$ = dspl$ + press$
               pss$ = pss$ + "*"
            END IF
        END IF
    LOOP
    IF UCASE$(dspl$) = "LETMEIN" THEN 
        PRINT "Welcome to our servers, "; usr$; "!"
        PRINT "Press any key to end..."
        SLEEP
        END
    ELSE
        PRINT "Username and password do not compute!"
        PRINT "Press any key to end..."
        SLEEP
        END
    END IF
CASE ELSE
    PRINT "No user under that name: Try again..."
    PRINT "Press any key to end..."
    SLEEP
    END
END SELECT 
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

To complicated for me... ahh...
Image
Seb McClouth

Post by Seb McClouth »

Rattrapmax6, can I use your routine in qbinux, for the security-console?

grtz
Seb
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Sure,. won't hurt my feelings, I'll be most glad it wasn't a code waisted.. :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Seb McClouth

Post by Seb McClouth »

Thx mate. I'll give ya credit...

grtz
Seb
Post Reply