AX_PYTHON_MODULE([pakfire], [fatal])
AX_PYTHON_MODULE([parted], [fatal])
+AX_PYTHON_MODULE([pwquality], [fatal])
AX_PYTHON_MODULE([pytz], [fatal])
AX_PYTHON_MODULE([snack], [fatal])
###############################################################################
import logging
+import pwquality
import snack
from .errors import *
class PasswordWindow(ButtonsWindow):
+ def __init__(self, *args, **kwargs):
+ ButtonsWindow.__init__(self, *args, **kwargs)
+
+ # Initialize pwquality
+ self.pwquality = pwquality.PWQSettings()
+
@property
def default_buttons(self):
return (
password1 = self.password1.value()
password2 = self.password2.value()
- # Has something been entered?
- if not password1:
- self.tui.message(
- _("Error"),
- _("You must enter a password"),
- buttons=[_("OK")],
- )
- raise TryAgainError
+ try:
+ # Has something been entered?
+ if not password1:
+ raise TryAgainError(_("You must enter a password"))
- # Do the passwords match?
- if not password1 == password2:
+ # Do the passwords match?
+ elif not password1 == password2:
+ raise TryAgainError(_("The entered passwords do not match"))
+
+ # Check if the password is strong enough
+ try:
+ self.pwquality.check(password1, None, "root")
+
+ except pwquality.PWQError as e:
+ code, message = e.args
+
+ # Show the message to the user
+ raise TryAgainError("%s" % message) from e
+
+ except TryAgainError as e:
self.tui.message(
_("Error"),
- _("The entered passwords do not match"),
- buttons=[_("OK")],
+ "%s" % e,
+ buttons=[_("OK")]
)
- raise TryAgainError
+
+ # Re-raise the error
+ raise e
# Return the password to the caller
return password1