0

how should i save data like {username , passwords} to disk for later retrieval so that it cannot be opend and read in by a text editor?

3
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by krystosan
0

I would recommend using the pickle library with the protocol set to 2. This is a binary format that should be unreadable in a text editor.

Mind you, this means that any Python program that uses your class can still un-pickle and read it. For added security, I would suggest looking into one-way cryptographic hashes (such as SHA224 or MD5) as a way of making the password unreadable: since you only need to confirm that the input password matches the stored one, you only need compare the hash of the password to the hash of the input. This makes it so that you don't need to store the password in a form that can be restored at all. This is in fact how virtually every password system in use today works, AFAIK.

0
try:
    import cPickle as pickle
except:
       import pickle

data=[{'a':'A','b':2,'c':3.0}]

print 'DATA:',(data)

data_string = pickle.dumps(data)
print 'Pickle:',data_string

got it

Edited by krystosan: it was dumps() not dump()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.