storing passwords in class variables in python
I'm working on a python script that stores ssh passwords only during the current session. What I'm doing is declaring a class variable credentials = {}. 开发者_开发问答When the script needs access to a specific server, it checks in credentials to see if credentials['server'] exists. If it does, it uses the password there, if it doesn't, it prompts the user.
This is all working fine, but I'm just wondering if that's a bad way of implementing this? This isn't running anywhere critical that I need to be THAT concerned about security. I was just thinking it'd be nice if I could declare credentials as private.
Is this a reasonable approach? Is there a more pythonic way to do this or one that's better suited for how python deals with class member access?
A bit of a digression, but when I've built scripts do this in the past, the security minded recommended using an ssh-agent approach. The agent is a background processes, independent of the python but running under the same user, that will store the credentials. Then the script doesn't need to worry about prompting or handling passwords at all.
精彩评论