②用python的shelve包持久化存储密码

存储密码

1
2
3
4
5
6
7
8
9
import shelve
import win32api
import win32con
with shelve.open('password') as db:
db['dingding'] = 'Your_dingding_Password'
db['xiaoheiban'] = 'Your_xiaoheiban_Password'
win32api.SetFileAttributes('password.dir', win32con.FILE_ATTRIBUTE_HIDDEN)
win32api.SetFileAttributes('password.bak', win32con.FILE_ATTRIBUTE_HIDDEN)
win32api.SetFileAttributes('password.dat', win32con.FILE_ATTRIBUTE_HIDDEN)

读取密码

1
2
3
4
5
6
#获得保存的密码
def getPassword(key):
db = shelve.open(cd.passwordFile)
retValue = db[key]
db.close()
return retValue