Just a simple login that uses a dictionary. Don't know if it would work on a console. Plus I can't figure out a way to add something to the dictionary while the program is running.
1 2 3 4 5 6 7 | database={'name': '1234', 'name2': '5678', 'name3': '9012'}
name = raw_input('Enter username: ')
ask = raw_input('Enter pin: ')
if ask in database[name]:
print 'Welcome', name
else:
print 'Invalid code'
|
A couple of comments: first of all you seem to be starting out in Python so a mailing list or a forum might be a better place for this. Secondly, you are just checking for the password against a string using "in" which will be true for '1' or '2' or '3' or '4' for your first user. In fact passwords should never be stored unencrypted and usually a "salt" is added to the encryption to obfuscate the result of hash function. For the same reason, we don't want to let a hacker know if they have the right username but not the right password, an error is usually returned if either is incorrect and errors are best reported by raising an exception. You might like to use the following as a starting point for further exploration.
What he said. Recipes should be interesting or novel or solve difficult problems. This is beginner stuff, and it's simply bad code. I'm not trying to get on your case for being a beginner--but if you're a beginner, you aren't ready to post examples.
Problems with this code:
To add new things to a dictionary while the program is running, try something like the following:
Good luck with Python, and I hope to see you back here when you have something more interesting to share.