Hi I was wondering how to make a program that can remember usernames and passwords even if you close the shell
-
1You could look into the pickle module, but you should be careful as storing passwords in a non-secure format could be dangerous. – Mitch Phillipson Jan 09 '13 at 22:53
-
2You could store them in a file. – Blender Jan 09 '13 at 22:53
-
@Blender a database would be the more usual way. – Mark Ransom Jan 09 '13 at 23:04
-
2Hey, I see you are relatively new to the site. A lot of times you'll get better responses if you demonstrate in the question that you've tried to come up with a solution and been unable to. Just a sentence or two saying "I tried x but need help with y" or "I was thinking maybe x, is that a good idea?" will go a long way. – Clay Wardell Jan 09 '13 at 23:22
1 Answers
I think the best way to do this would be to store the combination of username and it's password hash in a database. I'm most familiar working with SQL databases, and that would work for you.
To elaborate on the concept of a password hash, you should never store passwords in plaintext -- hash them using hashlib. A hash function takes an input string and deterministically transforms it into a fixed length jumble of characters. Given the input, it is easy to determine the hash, but given the hash, it is very hard to determine an input that would have created it.
So, you'll need to hash the passwords when they are first set by the user, save the hashed value in the database, and then hash the input the user gives on login to check for a match.
All this having been said, if you are actually trying to implement a secure authentication system from scratch, you are probably in over your head. There are lots of nuances to security that even very good programmers may not be aware of, and there is a reason why many frameworks come with this type of feature built in.
But, if this is just a theoretical exercise, or a way to learn some programming techniques, then I'd start by looking at tutorials on using Python to interact with SQL databases.

- 14,846
- 13
- 44
- 65