Skip to content

Commit

Permalink
Merge branch 'RavetcoFX-d1'
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Oct 7, 2015
2 parents 5aadb1b + 1a04f6e commit b9b0547
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 16 deletions.
56 changes: 48 additions & 8 deletions files/usr/lib/cinnamon-settings-users/cinnamon-settings-users.py
Expand Up @@ -157,7 +157,7 @@ def __init__ (self, user, password_mask, group_mask):
self.set_modal(True)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_title("")
self.set_title(_("Change Password"))

table = DimmedTable()
table.add_labels([_("New password"), None, _("Confirm password")])
Expand Down Expand Up @@ -188,19 +188,19 @@ def __init__ (self, user, password_mask, group_mask):
self.show_password.connect('toggled', self._on_show_password_toggled)
table.attach(self.show_password, 1, 3, 3, 4)

self.set_border_width(6)

box = self.get_content_area()
box.add(table)
self.show_all()

self.infobar = Gtk.InfoBar()
self.infobar.set_message_type(Gtk.MessageType.ERROR)
label = Gtk.Label(_("An error occured. Your password was not changed."))
content = self.infobar.get_content_area()
content.add(label)
table.attach(self.infobar, 0, 3, 4, 5)

self.set_border_width(6)

box = self.get_content_area()
box.add(table)
self.show_all()

self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, _("Change"), Gtk.ResponseType.OK, )

self.set_passwords_visibility()
Expand Down Expand Up @@ -249,10 +249,41 @@ def _on_new_password_icon_released(self, widget, icon_pos, event):
def _on_show_password_toggled(self, widget):
self.set_passwords_visibility()

# Based on setPasswordStrength() in Mozilla Seamonkey, which is tri-licensed under MPL 1.1, GPL 2.0, and LGPL 2.1.
# Forked from Ubiquity validation.py
def password_strength(self, password):
upper = lower = digit = symbol = 0
for char in password:
if char.isdigit():
digit += 1
elif char.islower():
lower += 1
elif char.isupper():
upper += 1
else:
symbol += 1
length = len(password)

length = min(length,4)
digit = min(digit,3)
upper = min(upper,3)
symbol = min(symbol,3)
strength = (
((length * 0.1) - 0.2) +
(digit * 0.1) +
(symbol * 0.15) +
(upper * 0.1))
if strength > 1:
strength = 1
if strength < 0:
strength = 0
return strength

def _on_passwords_changed(self, widget):
self.infobar.hide()
new_password = self.new_password.get_text()
confirm_password = self.confirm_password.get_text()
strength = self.password_strength(new_password)
if new_password != confirm_password:
self.confirm_password.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_DIALOG_WARNING)
self.confirm_password.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, _("Passwords do not match"))
Expand All @@ -261,8 +292,17 @@ def _on_passwords_changed(self, widget):
if len(new_password) < 8:
self.strengh_label.set_text(_("Too short"))
self.strengh_indicator.set_fraction(0.0)
elif strength < 0.5:
self.strengh_label.set_text(_("Weak"))
self.strengh_indicator.set_fraction(0.2)
elif strength < 0.75:
self.strengh_label.set_text(_("Fair"))
self.strengh_indicator.set_fraction(0.4)
elif strength < 0.9:
self.strengh_label.set_text(_("Good"))
self.strengh_indicator.set_fraction(0.6)
else:
self.strengh_label.set_text(_("OK"))
self.strengh_label.set_text(_("Strong"))
self.strengh_indicator.set_fraction(1.0)

self.check_passwords()
Expand Down
56 changes: 48 additions & 8 deletions files/usr/lib/cinnamon-settings/modules/cs_user.py
Expand Up @@ -224,7 +224,7 @@ def __init__ (self):
self.set_modal(True)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_title("")
self.set_title(_("Change Password"))

table = Gtk.Table(6, 3)
table.set_border_width(6)
Expand Down Expand Up @@ -274,19 +274,19 @@ def __init__ (self):
self.show_password.connect('toggled', self._on_show_password_toggled)
table.attach(self.show_password, 1, 3, 4, 5)

self.set_border_width(6)

box = self.get_content_area()
box.add(table)
self.show_all()

self.infobar = Gtk.InfoBar()
self.infobar.set_message_type(Gtk.MessageType.ERROR)
label = Gtk.Label.new(_("An error occured. Your password was not changed."))
content = self.infobar.get_content_area()
content.add(label)
table.attach(self.infobar, 0, 3, 5, 6)

self.set_border_width(6)

box = self.get_content_area()
box.add(table)
self.show_all()

self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, _("Change"), Gtk.ResponseType.OK, )

self.set_passwords_visibility()
Expand Down Expand Up @@ -361,10 +361,41 @@ def _on_current_password_changed(self, widget, event):
self.correct_current_password = True
self.check_passwords()

# Based on setPasswordStrength() in Mozilla Seamonkey, which is tri-licensed under MPL 1.1, GPL 2.0, and LGPL 2.1.
# Forked from Ubiquity validation.py
def password_strength(self, password):
upper = lower = digit = symbol = 0
for char in password:
if char.isdigit():
digit += 1
elif char.islower():
lower += 1
elif char.isupper():
upper += 1
else:
symbol += 1
length = len(password)

length = min(length,4)
digit = min(digit,3)
upper = min(upper,3)
symbol = min(symbol,3)
strength = (
((length * 0.1) - 0.2) +
(digit * 0.1) +
(symbol * 0.15) +
(upper * 0.1))
if strength > 1:
strength = 1
if strength < 0:
strength = 0
return strength

def _on_passwords_changed(self, widget):
self.infobar.hide()
new_password = self.new_password.get_text()
confirm_password = self.confirm_password.get_text()
strength = self.password_strength(new_password)
if new_password != confirm_password:
self.confirm_password.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_DIALOG_WARNING)
self.confirm_password.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, _("Passwords do not match"))
Expand All @@ -373,8 +404,17 @@ def _on_passwords_changed(self, widget):
if len(new_password) < 8:
self.strengh_label.set_text(_("Too short"))
self.strengh_indicator.set_fraction(0.0)
elif strength < 0.6:
self.strengh_label.set_text(_("Weak"))
self.strengh_indicator.set_fraction(0.2)
elif strength < 0.75:
self.strengh_label.set_text(_("Fair"))
self.strengh_indicator.set_fraction(0.4)
elif strength < 0.9:
self.strengh_label.set_text(_("Good"))
self.strengh_indicator.set_fraction(0.6)
else:
self.strengh_label.set_text(_("OK"))
self.strengh_label.set_text(_("Strong"))
self.strengh_indicator.set_fraction(1.0)

self.check_passwords()
Expand Down

0 comments on commit b9b0547

Please sign in to comment.