Skip to content

Commit

Permalink
Merge pull request #5 from 8go/suggest-passwords
Browse files Browse the repository at this point in the history
added a Generate-Random-Password button to GUI
  • Loading branch information
8go committed Apr 26, 2017
2 parents 7062130 + 3bce6d1 commit 2209339
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions TrezorPass.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def createPassword(self):
if self.selectedGroup is None:
return
group = self.pwMap.groups[self.selectedGroup]
dialog = AddPasswordDialog()
dialog = AddPasswordDialog(self.pwMap.trezor)
if not dialog.exec_():
return

Expand Down Expand Up @@ -389,7 +389,7 @@ def editPassword(self, item):
except CallException:
return

dialog = AddPasswordDialog()
dialog = AddPasswordDialog(self.pwMap.trezor)
entry = group.entry(row)
dialog.keyEdit.setText(s2q(entry[0]))
dialog.pwEdit1.setText(s2q(decrypted))
Expand Down
20 changes: 7 additions & 13 deletions add_password_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="generatePasswordButton">
<property name="text">
<string>Generate password</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand All @@ -103,19 +110,6 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
24 changes: 23 additions & 1 deletion dialogs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from PyQt4 import QtGui, QtCore

import os
import base64
import hashlib

from ui_addgroup_dialog import Ui_AddGroupDialog
from ui_trezor_passphrase_dialog import Ui_TrezorPassphraseDialog
from ui_add_password_dialog import Ui_AddPasswordDialog
from ui_initialize_dialog import Ui_InitializeDialog
from ui_enter_pin_dialog import Ui_EnterPinDialog
from ui_trezor_chooser_dialog import Ui_TrezorChooserDialog

from encoding import q2s, s2q

class AddGroupDialog(QtGui.QDialog, Ui_AddGroupDialog):

def __init__(self, groups):
Expand Down Expand Up @@ -52,12 +58,14 @@ def passphrase(self):

class AddPasswordDialog(QtGui.QDialog, Ui_AddPasswordDialog):

def __init__(self):
def __init__(self, trezor):
QtGui.QDialog.__init__(self)
self.setupUi(self)
self.pwEdit1.textChanged.connect(self.validatePw)
self.pwEdit2.textChanged.connect(self.validatePw)
self.showHideButton.clicked.connect(self.switchPwVisible)
self.generatePasswordButton.clicked.connect(self.generatePassword)
self.trezor = trezor

def key(self):
return self.keyEdit.text()
Expand Down Expand Up @@ -86,6 +94,20 @@ def switchPwVisible(self):

self.pwEdit1.setEchoMode(newMode)
self.pwEdit2.setEchoMode(newMode)

def generatePassword(self):
trezor_entropy = self.trezor.get_entropy(32)
urandom_entropy = os.urandom(32)
passwdBin = hashlib.sha256(trezor_entropy + urandom_entropy).digest()
# base85 encoding not yet implemented in Python 2.7, (requires Python 3+)
# so we use base64 encoding
# remove the base64 buffer char =, remove easily confused chars 0 and O, as well as I and l
passwdB64 = base64.urlsafe_b64encode(passwdBin).translate(None, '=0OIl')
# print "bin =", passwdBin, ", base =", passwdB64, " binlen =", len(passwdBin), "baselen =", len(passwdB64)
# instead of setting the values, we concatenate them to the existing values
# This way, by clicking the "Generate password" button one can create an arbitrary long random password.
self.pwEdit1.setText(self.pw1() + s2q(passwdB64))
self.pwEdit2.setText(self.pw2() + s2q(passwdB64))

class InitializeDialog(QtGui.QDialog, Ui_InitializeDialog):

Expand Down
Binary file modified screenshots-version-2/trezorpass-screenshot-large-comment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2209339

Please sign in to comment.