-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
95 lines (77 loc) · 3.41 KB
/
password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright (c) 2020 Vishnu J. Seesahai
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
import subprocess, os, sys, json, threading, signal, traceback, rpcworker
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
#from resource import resource_path
from rpcworker import progress_fn, thread_complete
_translate = QCoreApplication.translate
def resource_path(relative_path):
#dir = QDir.currentPath()
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath('.'), relative_path)
def change_pass(uname, pwd, progress_callback):
global err
try:
cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet walletpassphrasechange " + old_pwd + " " + new_pwd
result, err = subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
result = result.decode('utf-8')
err = err.decode('utf-8')
if err:
print('Error:', err)
return result
except subprocess.CalledProcessError as e:
print('Failed to retrieve public key.', e.output)
def change_pass_s(uname, pwd):
global err
try:
cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet walletpassphrasechange " + old_pwd + " " + new_pwd
result, err = subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
result = result.decode('utf-8')
err = err.decode('utf-8')
if err:
print('Error:', err)
print_result(result)
except subprocess.CalledProcessError as e:
print('Failed to retrieve public key.', e.output)
return
def change(u, p, op, np, win, state, pool, sync):
global window, uname, pwd, worker_state_active, old_pwd, new_pwd
uname = u
pwd = p
worker_state_active = state
threadpool = pool
old_pwd = op
new_pwd = np
window = win
print("sync", sync)
# Pass the function to execute
if not worker_state_active['PASS_CHNG']:
if not sync:
worker_state_active['PASS_CHNG'] = True
worker = rpcworker.Worker(change_pass, uname, pwd) # Any other args, kwargs are passed to the run function
worker.signals.result.connect(print_result)
worker.signals.finished.connect(thread_complete)
worker.signals.progress.connect(progress_fn)
threadpool.start(worker)
else:
change_pass_s(uname, pwd)
def print_result(result):
# Relock wallet.
lock = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet walletlock"
result_lock, err_lock = subprocess.Popen(resource_path(lock), shell=True, stdout=subprocess.PIPE).communicate()
if not err:
msg_box_13 = QtWidgets.QMessageBox()
msg_box_13.setText(_translate("MainWindow",'Your password has been changed.'))
msg_box_13.exec()
elif "Incorrect passphrase" in err:
msg_box_13 = QtWidgets.QMessageBox()
msg_box_13.setText(_translate("MainWindow",'Your password has not been changed. Please make sure your old password was entered correctly.'))
msg_box_13.exec()
else:
msg_box_13 = QtWidgets.QMessageBox()
msg_box_13.setText(_translate("MainWindow",'Your password has not been changed.'))
msg_box_13.exec()
worker_state_active['PASS_CHNG'] = False