Skip to content

Commit

Permalink
Fixes & Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
NotStatilko committed Jun 15, 2021
1 parent 90a91a8 commit 5aa64d9
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions uiScrypt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from PyQt5 import QtWidgets, QtCore
from ui_Scrypt import Ui_mainWindow
from hashlib import scrypt

from hashlib import scrypt as scrypt_
from sys import exit as sys_exit
from base64 import urlsafe_b64encode
from secrets import token_bytes #will be used for animation

from multiprocessing import Process, Queue

def scrypt(queue: Queue, **kwargs) -> None:
'''Will put resulted key to the queue.'''
s = scrypt_(**kwargs)
queue.put(s)

class uiScrypt(QtWidgets.QMainWindow):
def __init__(self):
super(uiScrypt, self).__init__()
Expand All @@ -18,7 +27,9 @@ def __init__(self):
}
for i in self.ledits:
i.hide()


self.ui.lineEdit_2.setFocus()

self.ui.pushButton_2.hide() #generate another
self.ui.label_7.hide() #in process label

Expand All @@ -33,7 +44,7 @@ def __init__(self):

self.ui.radioButton.clicked.connect(self.show_text)
self.ui.radioButton_2.clicked.connect(self.show_text)

self.ui.pushButton.setDefault(True)
self.ui.pushButton_2.setDefault(True)

Expand Down Expand Up @@ -61,14 +72,15 @@ def hide_all_empty_errors(self):

def make_password_clicked(self):
self.hide_all_empty_errors()
self.all_is_valid = True

for k,v in self.ledits.items():
if not v.text():
k.show(); self.all_is_valid = False
try:
n = int(self.ui.lineEdit_6.text())
r = int(self.ui.lineEdit_5.text())
p = int(self.ui.lineEdit.text())
self.all_is_valid = True
except:
self.all_is_valid = False
self.ui.label_12.show()
Expand All @@ -78,23 +90,37 @@ def make_password_clicked(self):
self.ui.label_5.hide()
self.ui.label_7.show()
self.ui.lineEdit_4.show()
self.ui.lineEdit_4.setFocus()
try:
key = scrypt(
password = self.ui.lineEdit_2.text().encode(),
salt = self.ui.lineEdit_3.text().encode(),
n = n, r = r, p = p, dklen=32,
maxmem = 128 * r * (n + p + 2)
)
queue = Queue()

p = Process(
target=scrypt, args=(queue,),
kwargs={
'password': self.ui.lineEdit_2.text().encode(),
'salt': self.ui.lineEdit_3.text().encode(),
'n': n, 'r': r, 'p': p, 'dklen': 32,
'maxmem': (128 * r * (n + p + 2))
}
); p.start()
while not queue.qsize():
QtCore.QCoreApplication.processEvents()
self.ui.lineEdit_4.setText(
urlsafe_b64encode(token_bytes()).decode()
)
else:
key = queue.get(); p.join()

self.ui.label_7.hide()
self.ui.label_8.show()
self.ui.lineEdit_4.setText(urlsafe_b64encode(key).decode())
self.ui.lineEdit_4.selectAll()
self.ui.lineEdit_4.setFocus()
self.ui.lineEdit_4.show()
self.ui.pushButton_2.show()
except:
self.erase_to_start()
self.ui.label_12.show()
self.all_is_valid = False
else:
self.ui.label_7.hide()
self.ui.label_8.show()
self.ui.lineEdit_4.setText(urlsafe_b64encode(key).decode())
self.ui.lineEdit_4.show()
self.ui.pushButton_2.show()

def hide_with_edit(self):
self.hide_all_empty_errors()
Expand All @@ -107,6 +133,7 @@ def erase_to_start(self):
self.ui.lineEdit_4.hide()
self.ui.label_5.show()
self.ui.pushButton.show()
self.ui.lineEdit_2.setFocus()

def closeEvent(self,event):
self.close(); sys_exit()
Expand Down

1 comment on commit 5aa64d9

@NotStatilko
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o Fixed app freeze during password creation;
o Fixed cursor position (after & before password making);
o Fixed bug with Scrypt configuration (non-security issue);
o After password creation it will be auto-selected;
o Password making animation was added.

Now app will be slightly slower (because of Process creation).

Please sign in to comment.