Password creation


#1



https://www.codecademy.com/courses/introduction-to-python-6WeG3/0/1?curriculum_id=4f89dab3d788890003000096 don't worry I DO understand how to do basic syntax...

I can't seem to get the code to create a simple password system where it will print the line and send the user to the next line.

I expected the code to allow you to enter the username and password, then send you to the next section.


print "Welcome to JARVIS 2.0_4 alpha"
#hint: usernames are JARVIS Admin and Guest
USR='JARVIS Admin'
PASS='JC2137'
Guest='Guest'
Gpasswrd=""

startup=raw_input("What is the username?")
if startup == USR:
    print "Please print the password"
    return PASSWORD
if startup = Guest:
    print "Welcome Guest."
    return GPASS
else:
    print "Intruder alert!!!"
    return startup
PASSWORD=input("Please enter the password")
if PASSWORD = PASS:
    print "Welcome Admin to JARVIS 2.0_4" 
    return ADM
else:
    print "INTRUDER ALERT!!!"
    return startup 

GPASS=input("Press enter.")
if GPASS = Gpasswrd
    print "Welcome Guest."
    return GDM
else:
    return GPASS
    
ADM = ("Welcome to JARVIS Admin. I have been updated.")
GDM = ("Welcome to JARVIS Guest. I have been updated.")


#2

i see one huge problems: return needs to be inside a function. It can't be used outside a function, or like you use it now


#3

@xtremeshooter

So when you create a user you should be adding it to a list as it is best suited for this task. Then comes the problem of a password, it then changes the best to a dictionary as you have a key with a value associated with it.

Python User Dictionary

USR = {
    'JARVIS': 'JC2137',
    'Admin': 'password',
    'Guest': None
}

So much cleaner like this.

Now to check if someone enters a password and username,

Python User Test

ask_usr = raw_input("What is your user name?\n")
ask_pass = raw_input("Enter password")
if USR.get(ask_usr, 'Not Found') == ask_pass:
    print("Welcome {}, please enjoy your stay!".format(ask_usr))
else:
    print("Intruder Alert")

When you are building programs ensure you think about your purpose as it will help you solve the issue with the least amount of code. This also ensures it is readable and more secure.

Also @stetim94 is totally correct, a return outside of a function does bad things to the IDE and interpreter.