76 lines
2.1 KiB
Python
Executable File
76 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import hashlib
|
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
from PyQt5.QtWidgets import QMainWindow
|
|
from PyQt5.QtWidgets import QLineEdit
|
|
from PyQt5.QtWidgets import QVBoxLayout
|
|
from PyQt5.QtWidgets import QWidget
|
|
from PyQt5.QtGui import QCursor
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtCore import QTimer
|
|
|
|
|
|
CORRECT_PASSWORD_HASH = '1d2e2b10cf9a5474612138ac00bc8b1e8fe895822ddc1e77e0edd023fcff4565'
|
|
|
|
class FullScreenWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.title = 'plock'
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
self.setWindowTitle(self.title)
|
|
|
|
self.central_widget = QWidget()
|
|
self.setCentralWidget(self.central_widget)
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
self.password_field = QLineEdit()
|
|
self.password_field.setEchoMode(QLineEdit.Password)
|
|
self.password_field.returnPressed.connect(self.check_password)
|
|
self.password_field.setFixedWidth(200)
|
|
|
|
layout.addWidget(self.password_field, 0, Qt.AlignCenter)
|
|
|
|
self.central_widget.setLayout(layout)
|
|
|
|
self.showFullScreen()
|
|
|
|
def check_password(self):
|
|
entered_password_hash = hashlib.sha256(self.password_field.text().encode('utf-8')).hexdigest()
|
|
if entered_password_hash == CORRECT_PASSWORD_HASH:
|
|
self.close()
|
|
|
|
def showEvent(self, event):
|
|
super().showEvent(event)
|
|
QTimer.singleShot(100, self.grabKeyboardAndMouse)
|
|
|
|
def grabKeyboardAndMouse(self):
|
|
super().showFullScreen()
|
|
self.grabMouse()
|
|
self.grabKeyboard()
|
|
self.setCursor(QCursor(Qt.BlankCursor))
|
|
self.password_field.setFocus()
|
|
|
|
def keyPressEvent(self, event):
|
|
self.grabMouse()
|
|
self.grabKeyboard()
|
|
if event.key() == Qt.Key_Escape:
|
|
if event.modifiers() & Qt.ControlModifier:
|
|
print("Secure exit requested")
|
|
self.close()
|
|
else:
|
|
self.password_field.keyPressEvent(event)
|
|
|
|
def main() -> int:
|
|
app = QApplication(sys.argv)
|
|
ex = FullScreenWindow()
|
|
return app.exec_()
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|