Save web password only if the connection is successful

pull/3/head
remittor 4 years ago
parent f0066a8ce8
commit 5fd5d2fe32

@ -144,10 +144,10 @@ class Gateway():
if not self.nonce_key or not self.mac_address: if not self.nonce_key or not self.mac_address:
die("Xiaomi Mi Wi-Fi device is wrong model or not the stock firmware in it.") die("Xiaomi Mi Wi-Fi device is wrong model or not the stock firmware in it.")
nonce = "0_" + self.mac_address + "_" + str(int(time.time())) + "_" + str(random.randint(1000, 10000)) nonce = "0_" + self.mac_address + "_" + str(int(time.time())) + "_" + str(random.randint(1000, 10000))
if not self.webpassword: web_pass = self.webpassword
self.webpassword = input("Enter device WEB password: ") if not web_pass:
password = self.webpassword web_pass = input("Enter device WEB password: ")
account_str = (password + self.nonce_key).encode('utf-8') account_str = (web_pass + self.nonce_key).encode('utf-8')
account_str = hashlib.sha1(account_str).hexdigest() account_str = hashlib.sha1(account_str).hexdigest()
password = (nonce + account_str).encode('utf-8') password = (nonce + account_str).encode('utf-8')
password = hashlib.sha1(password).hexdigest() password = hashlib.sha1(password).hexdigest()
@ -158,7 +158,9 @@ class Gateway():
try: try:
stok = re.findall(r'"token":"(.*?)"',r1.text)[0] stok = re.findall(r'"token":"(.*?)"',r1.text)[0]
except Exception: except Exception:
self.webpassword = ""
die("WEB password is not correct!") die("WEB password is not correct!")
self.webpassword = web_pass
self.stok = stok self.stok = stok
@property @property

Loading…
Cancel
Save