Skip to content

Commit

Permalink
make list of "easy to mistake pairs of letters" configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sommer committed Dec 30, 2018
1 parent 3620067 commit 8b6fedb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
Binary file modified locale/de/LC_MESSAGES/loxodo.mo
Binary file not shown.
15 changes: 9 additions & 6 deletions locale/de/LC_MESSAGES/loxodo.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Loxodo 0.0-git\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-26 01:57+0100\n"
"PO-Revision-Date: 2018-12-26 01:58+0100\n"
"POT-Creation-Date: 2018-12-30 18:07+0100\n"
"PO-Revision-Date: 2018-12-30 18:07+0100\n"
"Last-Translator: Christoph Sommer <[email protected]>\n"
"Language-Team: Christoph Sommer <[email protected]>\n"
"Language: de_DE\n"
Expand Down Expand Up @@ -127,13 +127,13 @@ msgid "Generated Password Length"
msgstr "Generiere Passwörter mit Länge"

#: ../src/frontends/wx/settings.py:51
msgid "Avoid easy to mistake chars"
msgstr "Ohne leicht zu verwechselnde Zeichen"

#: ../src/frontends/wx/settings.py:53
msgid "Alphabet"
msgstr "Alphabet"

#: ../src/frontends/wx/settings.py:53
msgid "Avoid Bigrams"
msgstr "Vermeide Bigramme"

#: ../src/frontends/wx/settings.py:76
msgid "Settings"
msgstr "Einstellungen"
Expand Down Expand Up @@ -288,6 +288,9 @@ msgstr "Konnte Passwort für \"%s\" nicht in Zwischenablage kopieren"
msgid "Could not load python module \"webbrowser\" needed to open \"%s\""
msgstr "Konnte Python-Modul “webbrowser” nicht laden, um “%s” zu öffnen"

#~ msgid "Avoid easy to mistake chars"
#~ msgstr "Ohne leicht zu verwechselnde Zeichen"

#~ msgid "Changed title of \"%s\""
#~ msgstr "Titel von \"%s\" geändet"

Expand Down
6 changes: 3 additions & 3 deletions locale/loxodo.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-26 01:57+0100\n"
"POT-Creation-Date: 2018-12-30 18:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -128,11 +128,11 @@ msgid "Generated Password Length"
msgstr ""

#: ../src/frontends/wx/settings.py:51
msgid "Avoid easy to mistake chars"
msgid "Alphabet"
msgstr ""

#: ../src/frontends/wx/settings.py:53
msgid "Alphabet"
msgid "Avoid Bigrams"
msgstr ""

#: ../src/frontends/wx/settings.py:76
Expand Down
20 changes: 10 additions & 10 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def __init__(self):
self._basescript = None
self.recentvaults = []
self.pwlength = 10
self.reduction = False
self.search_notes = False
self.search_passwd = False
self.alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
self.alphabet = "abcdefghikmnopqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ_"
self.avoid_bigrams = "cl mn nm nn rn vv VV"

self._fname = self.get_config_filename()
self._parser = SafeConfigParser()
Expand All @@ -53,16 +53,9 @@ def __init__(self):
break
self.recentvaults.append(self._parser.get("base", "recentvaults" + str(num)))

if self._parser.has_option("base", "alphabet"):
self.alphabet = int(self._parser.get("base", "alphabet"))

if self._parser.has_option("base", "pwlength"):
self.pwlength = int(self._parser.get("base", "pwlength"))

if self._parser.has_option("base", "alphabetreduction"):
if self._parser.get("base", "alphabetreduction") == "True":
self.reduction = True

if self._parser.has_option("base", "search_notes"):
if self._parser.get("base", "search_notes") == "True":
self.search_notes = True
Expand All @@ -71,6 +64,12 @@ def __init__(self):
if self._parser.get("base", "search_passwd") == "True":
self.search_passwd = True

if self._parser.has_option("base", "alphabet"):
self.alphabet = self._parser.get("base", "alphabet")

if self._parser.has_option("base", "avoid_bigrams"):
self.avoid_bigrams = self._parser.get("base", "avoid_bigrams")

if not os.path.exists(self._fname):
self.save()

Expand All @@ -95,9 +94,10 @@ def save(self):
break

self._parser.set("base", "pwlength", str(self.pwlength))
self._parser.set("base", "alphabetreduction", str(self.reduction))
self._parser.set("base", "search_notes", str(self.search_notes))
self._parser.set("base", "search_passwd", str(self.search_passwd))
self._parser.set("base", "alphabet", str(self.alphabet))
self._parser.set("base", "avoid_bigrams", str(self.avoid_bigrams))
filehandle = open(self._fname, 'w')
self._parser.write(filehandle)
filehandle.close()
Expand Down
15 changes: 5 additions & 10 deletions src/frontends/wx/recordframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _on_toggle_passwd_mask(self, dummy):
self._tc_passwd.SetFocus()

def _on_generate_passwd(self, dummy):
_pwd = self.generate_password(alphabet=config.alphabet,pwd_length=config.pwlength,allow_reduction=config.reduction)
_pwd = self.generate_password(alphabet=config.alphabet,pwd_length=config.pwlength,avoid_bigrams=config.avoid_bigrams)
self._tc_passwd.SetValue(_pwd)

@staticmethod
Expand All @@ -190,20 +190,15 @@ def _urandom(count):
return retval

@staticmethod
def generate_password(alphabet="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_", pwd_length=8, allow_reduction=False):
# remove some easy-to-mistake characters
if allow_reduction:
for _chr in "0OjlI1":
alphabet = alphabet.replace(_chr, "")

def generate_password(alphabet="0123456789", pwd_length=8, avoid_bigrams=""):
# iteratively pick one character from this alphabet to assemble password
last_chr = "x"
pwd = ""
for dummy in range(pwd_length):
# temporarily reduce alphabet to avoid easy-to-mistake character pairs
# temporarily reduce alphabet to avoid easy-to-mistake bigrams
alphabet2 = alphabet
if allow_reduction:
for _chr in ('cl', 'mn', 'nm', 'nn', 'rn', 'vv', 'VV'):
if len(avoid_bigrams) > 1:
for _chr in (avoid_bigrams.split(" ")):
if last_chr == _chr[0]:
alphabet2 = alphabet.replace(_chr[1],"")

Expand Down
8 changes: 4 additions & 4 deletions src/frontends/wx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def __init__(self, parent):

_sz_main.Add(_sz_fields, 1, wx.EXPAND | wx.GROW)

self._cb_reduction = self._add_a_checkbox(_sz_fields,_("Avoid easy to mistake chars") + ":")

self._tc_alphabet = self._add_a_textcontrol(_sz_fields,_("Alphabet")+ ":",config.alphabet)

self._tc_avoid_bigrams = self._add_a_textcontrol(_sz_fields,_("Avoid Bigrams")+ ":",config.avoid_bigrams)

_sz_fields.AddGrowableCol(1)

_ln_line = wx.StaticLine(self.panel, -1, size=(20, -1), style=wx.LI_HORIZONTAL)
Expand Down Expand Up @@ -117,7 +117,7 @@ def update_fields(self):
"""
self._sc_length.SetValue(config.pwlength)
self._tc_alphabet.SetValue(config.alphabet)
self._cb_reduction.SetValue(config.reduction)
self._tc_avoid_bigrams.SetValue(config.avoid_bigrams)
self._search_notes.SetValue(config.search_notes)
self._search_passwd.SetValue(config.search_passwd)

Expand All @@ -126,10 +126,10 @@ def _apply_changes(self, dummy):
Update source from fields
"""
config.pwlength = self._sc_length.GetValue()
config.reduction = self._cb_reduction.GetValue()
config.search_notes = self._search_notes.GetValue()
config.search_passwd = self._search_passwd.GetValue()
config.alphabet = self._tc_alphabet.GetValue()
config.avoid_bigrams = self._tc_avoid_bigrams.GetValue()
config.save()

def _on_cancel(self, dummy):
Expand Down

0 comments on commit 8b6fedb

Please sign in to comment.