Add password quality

This commit is contained in:
Mauricio Baeza 2021-10-07 22:27:55 -05:00
parent 7ddce709df
commit fa751a207e
6 changed files with 55 additions and 14 deletions

View File

@ -79,13 +79,13 @@ LICENSE_ES = LICENSE_EN
INFO = { INFO = {
'en': { 'en': {
'display_name': 'My first extension', 'display_name': 'ZAZ Pass',
'description': 'My great extension', 'description': 'Generate passwords',
'license': LICENSE_EN, 'license': LICENSE_EN,
}, },
'es': { 'es': {
'display_name': 'Mi primer extensión', 'display_name': 'ZAZ Pass',
'description': 'Mi gran extensión', 'description': 'Generar contraseñas',
'license': LICENSE_ES, 'license': LICENSE_ES,
}, },
} }

Binary file not shown.

View File

@ -3,8 +3,8 @@
<identifier value="net.elmau.zaz.pass"/> <identifier value="net.elmau.zaz.pass"/>
<version value="0.1.0"/> <version value="0.1.0"/>
<display-name> <display-name>
<name lang="en">My first extension</name> <name lang="en">ZAZ Pass</name>
<name lang="es">Mi primer extensión</name> <name lang="es">ZAZ Pass</name>
</display-name> </display-name>
<extension-description> <extension-description>
<src lang="en" xlink:href="description/desc_en.txt"/> <src lang="en" xlink:href="description/desc_en.txt"/>

View File

@ -1 +1 @@
My great extension Generate passwords

View File

@ -1 +1 @@
Mi gran extensión Generar contraseñas

View File

@ -100,6 +100,16 @@ def _password_copy():
return return
def _get_quality(strength):
if strength <= 0.33:
quality = _('Week')
elif strength <= 0.66:
quality = _('Medium')
else:
quality = _('Excellent')
return quality
def _password_generate(id_extension): def _password_generate(id_extension):
config = app.get_config('setting', prefix=PREFIX) config = app.get_config('setting', prefix=PREFIX)
dialog = _create_dialog(id_extension) dialog = _create_dialog(id_extension)
@ -121,7 +131,9 @@ def _password_generate(id_extension):
dialog.chk_punctuation.value = punctuation dialog.chk_punctuation.value = punctuation
dialog.txt_length.value = length dialog.txt_length.value = length
dialog.txt_password.value = _generate(dialog) stats = PasswordStats(_generate(dialog))
dialog.txt_password.value = stats.password
dialog.lbl_quality.value = _get_quality(stats.strength())
dialog.open() dialog.open()
return return
@ -171,6 +183,7 @@ class Controllers(object):
def _new_password(self, save=True): def _new_password(self, save=True):
stats = PasswordStats(_generate(self.d)) stats = PasswordStats(_generate(self.d))
self.d.txt_password.value = stats.password self.d.txt_password.value = stats.password
self.d.lbl_quality.value = _get_quality(stats.strength())
if save: if save:
self._save_config() self._save_config()
return return
@ -203,13 +216,14 @@ class Controllers(object):
@app.catch_exception @app.catch_exception
def _create_dialog(id_extension): def _create_dialog(id_extension):
BUTTON_WH = 16 BUTTON_WH = 16
CHK_HEIGHT = 10
CHK_WIDTH = 25 CHK_WIDTH = 25
attr = dict( attr = dict(
Name = 'Dialog', Name = 'Dialog',
Title = _('Generate Password'), Title = _('Generate Password'),
Width = 200, Width = 200,
Height = 100, Height = 120,
) )
dialog = app.create_dialog(attr) dialog = app.create_dialog(attr)
dialog.id = id_extension dialog.id = id_extension
@ -266,7 +280,7 @@ def _create_dialog(id_extension):
Spin = True, Spin = True,
Value = 25, Value = 25,
ValueStep = 1, ValueStep = 1,
ValueMin = 10, ValueMin = 5,
ValueMax = 100, ValueMax = 100,
) )
dialog.add_control(attr) dialog.add_control(attr)
@ -276,7 +290,7 @@ def _create_dialog(id_extension):
Name = 'chk_letters', Name = 'chk_letters',
Label = 'A-Z', Label = 'A-Z',
Width = CHK_WIDTH, Width = CHK_WIDTH,
Height = BUTTON_WH, Height = CHK_HEIGHT,
) )
dialog.add_control(attr) dialog.add_control(attr)
@ -285,7 +299,7 @@ def _create_dialog(id_extension):
Name = 'chk_letters2', Name = 'chk_letters2',
Label = 'a-z', Label = 'a-z',
Width = CHK_WIDTH, Width = CHK_WIDTH,
Height = BUTTON_WH, Height = CHK_HEIGHT,
) )
dialog.add_control(attr) dialog.add_control(attr)
@ -294,7 +308,7 @@ def _create_dialog(id_extension):
Name = 'chk_digits', Name = 'chk_digits',
Label = '0-9', Label = '0-9',
Width = CHK_WIDTH, Width = CHK_WIDTH,
Height = BUTTON_WH, Height = CHK_HEIGHT,
) )
dialog.add_control(attr) dialog.add_control(attr)
@ -303,7 +317,31 @@ def _create_dialog(id_extension):
Name = 'chk_punctuation', Name = 'chk_punctuation',
Label = string.punctuation, Label = string.punctuation,
Width = CHK_WIDTH * 4, Width = CHK_WIDTH * 4,
Height = CHK_HEIGHT,
)
dialog.add_control(attr)
attr = dict(
Type = 'Label',
Name = 'lbl_title_quality',
Label = _('Password Quality:'),
Width = 75,
Height = BUTTON_WH, Height = BUTTON_WH,
Border = app.Border.BORDER,
Align = app.RIGHT,
VerticalAlign = app.MIDDLE,
)
dialog.add_control(attr)
attr = dict(
Type = 'Label',
Name = 'lbl_quality',
Label = _('Poor'),
Width = 35,
Height = BUTTON_WH,
Border = app.Border.BORDER,
Align = app.CENTER,
VerticalAlign = app.MIDDLE,
) )
dialog.add_control(attr) dialog.add_control(attr)
@ -338,6 +376,9 @@ def _create_dialog(id_extension):
dialog.chk_digits.move(dialog.chk_letters2, x=3, y=0) dialog.chk_digits.move(dialog.chk_letters2, x=3, y=0)
dialog.chk_punctuation.move(dialog.chk_digits, x=3, y=0) dialog.chk_punctuation.move(dialog.chk_digits, x=3, y=0)
dialog.lbl_title_quality.move(dialog.chk_letters)
dialog.lbl_quality.move(dialog.lbl_title_quality, x=3, y=0)
dialog.center(dialog.cmd_insert, y=-5) dialog.center(dialog.cmd_insert, y=-5)
dialog.center(dialog.cmd_close, y=-5) dialog.center(dialog.cmd_close, y=-5)
dialog.center((dialog.cmd_close, dialog.cmd_insert)) dialog.center((dialog.cmd_close, dialog.cmd_insert))