Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510
Hello, i am a beginner programer using python, how can i make python understand multiple passwords, here is an example of what i mean:

password = input ("Enter Password to " \
"enter terminal: ")

if password == "Cyndi": -------here is where i need it to understand more than 1 password
print ("Access Granted ")

else:
print ("Access Denied")
print ("Contact System Administrator ")
input ("Press exit")
 
Solution
This is looking more and more like a class assignment so I'm going to decline to simply hand you an answer.

What you need to do is open the text file within your script and read it line by line until either a match is found or the end of the file is reached without finding a match. Place that code in a function that takes the password as a parameter and returns pass/fail as a return value, then act on that as necessary.

Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510


im sorry, i didnt make it clear, i want to make python accept more than 1 password, so instead of just "Cyndi" i can have another password it will recognize at the same time
 

Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510


ok could you explain in detail what i have to do
 

ex_bubblehead

Distinguished
Moderator
This is looking more and more like a class assignment so I'm going to decline to simply hand you an answer.

What you need to do is open the text file within your script and read it line by line until either a match is found or the end of the file is reached without finding a match. Place that code in a function that takes the password as a parameter and returns pass/fail as a return value, then act on that as necessary.
 
Solution

simonCode

Estimable
Dec 5, 2014
1
0
4,510
Hello,

your problem is, that function input() finding a variable in your script.
If you type Cyndi as argument in input(), script start finding a variable name Cyndi.
You have to use raw_input() function, that return what you expect.

fix:
password = raw_input(Enter Password to " \
"enter terminal: ")