Hardware Reference
In-Depth Information
Getting Input
Edit the door_controller.py code by adding the following class:
class KeyboardInput:
def getInput(self):
print “checking for input”
id = raw_input(“please enter your name: “)
password = raw_input(“please enter your password: “)
authToken = AuthToken(id,password)
return authToken
You need to tell the program to use this class to get input rather than the TestInput class.
Change the line
authInput = TestInput()
to
authInput = KeyboardInput()
Check that the code works; the door should open only if you type the name Andrew and the
password 1234 .
he next step is to implement the authentication block.
The Authentication Block
Authentication is about checking that someone is who he or she claims to be. You will proba-
bly use authentication systems many times a day. For example, you need to authenticate
yourself to use websites such as Facebook and Twitter.
he class you have written so far to do authentication is very simple; it checks to see if the
string passed to it matches a hard-coded value. his has a number of drawbacks, including
the following:
If anyone looks at the source code, it is possible for him or her to read your password.
Changing the password requires you to edit the source code.
A better solution is to store the password information separately, which is what you will do
next.
Search WWH ::




Custom Search