inspired by the recent discussion in which I was criticized, I rewrote the code for saving login data making significant changes.
In this new version of login files are not used for data storage, at frist use two keys are created randomly and stored in the system registry these are used to crypt the login data which are also saved in system registry
Note: for right work need to use lib in the attachment. All is tested on Win7 32/64 bit
Who want to discuss other work can create a discussion without make flame here thanks.
Code:
import os
import sys
import string
from _winreg import *
def __OnClickSaveButton(self):
id = self.idEditLine.GetText()
pwd = self.pwdEditLine.GetText()
self.__SaveAccountInfo(id, pwd)
def __SaveAccountInfo(self, user, passw):
try:
userid = self.__encrypt(user).replace(' ', '-')
passwd = self.__encrypt(passw).replace(' ', '-')
aReg = ConnectRegistry(None, HKEY_CURRENT_USER)
aKey = CreateKey(aReg, "software\\MyClientName\\")
SetValueEx(aKey, "user", 0, REG_SZ, userid)
SetValueEx(aKey, "pass", 0, REG_SZ, passwd)
CloseKey(aKey)
CloseKey(aReg)
self.PopupNotifyMessage("Info: Dati di Login salvati.")
except:
self.PopupNotifyMessage("Info: Errore Salvataggio dati di Login.")
return
def __LoadAccountInfo(self):
try:
login_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v user').readlines()
login_line = login_data[2].split()
login_value = login_line[2].replace('-', ' ').strip('\n')
passw_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v pass').readlines()
passw_line = passw_data[2].split()
passw_value = passw_line[2].replace('-', ' ').strip('\n')
user=self.__decrypt(login_value)
passw=self.__decrypt(passw_value)
return user, passw
except:
print "LoginWindow.__LoadAccountInfo - OpenError"
return -1, -1
def __encrypt(self, string):
aReg = ConnectRegistry(None, HKEY_CURRENT_USER)
try:
aKey = OpenKey(aReg, "software\\MyClientName\\")
except WindowsError:
try:
key1_value = app.GetRandom(1,127)
key2_value = app.GetRandom(1,32768)
aKey = CreateKey(aReg, "software\\MyClientName\\")
SetValueEx(aKey, "key1", 0, REG_DWORD, key1_value)
SetValueEx(aKey, "key2", 0, REG_DWORD, key2_value)
CloseKey(aKey)
CloseKey(aReg)
except:
CloseKey(aReg)
return
key1_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v key1').readlines()
key1_line = key1_data[2].split()
key1_value = int(key1_line[2], 16)
key2_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v key2').readlines()
key2_line = key2_data[2].split()
key2_value = int(key2_line[2], 16)
a = string
new_string = ''
for x in a:
new_string = new_string+str(int(ord(x) + key1_value) * key2_value)+' '
return new_string
def __decrypt(self, string):
aReg = ConnectRegistry(None, HKEY_CURRENT_USER)
try:
aKey = OpenKey(aReg, "software\\MyClientName\\")
except WindowsError:
CloseKey(aReg)
return
CloseKey(aKey)
CloseKey(aReg)
key1_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v key1').readlines()
key1_line = key1_data[2].split()
key1_value = int(key1_line[2], 16)
key2_data = os.popen('reg QUERY "HKEY_CURRENT_USER\software\MyClientName" /v key2').readlines()
key2_line = key2_data[2].split()
key2_value = int(key2_line[2], 16)
a = string
new_string = ''
b = a.split()
for x in b:
new_string = new_string+chr((int(x) / key2_value) - key1_value)
return new_string
d3m0n3






