Skip to content

Commit

Permalink
Fixed login verification thanks to Chadsr for new API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vfosterm committed Sep 13, 2020
1 parent 0678317 commit da929bb
Showing 1 changed file with 18 additions and 49 deletions.
67 changes: 18 additions & 49 deletions nord_nm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,58 +353,27 @@ def verify_credentials(self):
Verifies responses and updates GUI
"""
if self.user_input.text() and self.password_input.text():
self.statusbar.showMessage('Login Success', 2000)
self.username = self.user_input.text()
self.password = self.password_input.text()
self.repaint()
time.sleep(0.5)
self.hide()
self.main_ui()

else:
self.statusbar.showMessage('Username or password field cannot be empty, 2000')
# try:
# resp = requests.get('https://apself.statusbar.showMessage('Login Success', 2000)
# self.username = self.user_input.text()
# self.password = self.password_input.text()
# self.repaint()
# time.sleep(0.5)
# self.hide()
# self.main_ui()i.nordvpn.com/token/token/' + self.user_input.text(), timeout=5)
#
# if resp.status_code == requests.codes.ok:
# token_json = json.loads(resp.text)
# token = token_json['token']
# salt = token_json['salt']
# key = token_json['key']
#
# password_hash = hashlib.sha512(salt.encode() + self.password_input.text().encode())
# final_hash = hashlib.sha512(password_hash.hexdigest().encode() + key.encode())
#
# try:
# resp = requests.get('https://api.nordvpn.com/token/verify/' + token + '/' + final_hash.hexdigest(), timeout=5)
# if resp.status_code == requests.codes.ok:
# self.statusbar.showMessage('Login Success', 2000)
# self.username = self.user_input.text()
# self.password = self.password_input.text()
# self.repaint()
# time.sleep(0.5)
# self.hide()
# self.main_ui()
# else:
# self.statusbar.showMessage('Invalid Credentials', 2000)
# self.user_input.clear()
# self.password_input.clear()
# self.user_input.setFocus()
# except Exception as ex:
# self.statusbar.showMessage('Invalid Credentials', 2000)
# self.user_input.clear()
# self.password_input.clear()
# self.user_input.setFocus()
# else:
# self.statusbar.showMessage("API Error: could not fetch token", 2000)
# except Exception as ex:
# self.statusbar.showMessage("API Error: could not fetch token", 2000)
# self.get_api_data()
self.statusbar.showMessage('Username or password field cannot be empty', 2000)
try:
json_data = {'username': self.username, 'password': self.password}
resp = requests.post('https://api.nordvpn.com/v1/users/tokens', json=json_data, timeout=5)
if resp.status_code == 201:
self.statusbar.showMessage('Login Success', 2000)
self.repaint()
time.sleep(0.5)
self.hide()
self.main_ui()

else:
self.statusbar.showMessage('Invalid Username or Password', 2000)

except Exception as ex:
self.statusbar.showMessage("API Error: could not fetch token", 2000)
self.get_api_data()

def get_api_data(self):
"""
Expand Down

0 comments on commit da929bb

Please sign in to comment.