def import_various(context): """ Install the PwExpiryPlugin """ if context.readDataFile('collective_pwexpiry_default.txt') is None: return portal = context.getSite() ps = portal.portal_setup acl = getToolByName(portal, 'acl_users') installed = acl.objectIds() if 'pwexpiry' not in installed: addPwExpiryPlugin(acl, 'pwexpiry', 'PwExpiry Plugin') activatePluginInterfaces(portal, 'pwexpiry') for i in range(len(acl.plugins.listPluginIds(IChallengePlugin))): acl.plugins.movePluginsUp(IChallengePlugin, ['pwexpiry']) else: logger.info('pwexpiry already installed') if 'pwdisable' not in installed: addPwDisablePlugin(acl, 'pwdisable', 'PwDisable Plugin') activatePluginInterfaces(portal, 'pwdisable') for i in range(len(acl.plugins.listPluginIds(IChallengePlugin))): acl.plugins.movePluginsUp(IChallengePlugin, ['pwdisable']) else: logger.info('pwdisable already installed') if not IS_PLONE_5: profile = 'profile-collective.pwexpiry:plone4' ps.runAllImportStepsFromProfile(profile)
def import_various(context): """ Install the PwExpiryPlugin """ if context.readDataFile("collective_pwexpiry_default.txt") is None: return portal = context.getSite() ps = portal.portal_setup acl = getToolByName(portal, "acl_users") installed = acl.objectIds() if "pwexpiry" not in installed: addPwExpiryPlugin(acl, "pwexpiry", "PwExpiry Plugin") activatePluginInterfaces(portal, "pwexpiry") for i in range(len(acl.plugins.listPluginIds(IChallengePlugin))): acl.plugins.movePluginsUp(IChallengePlugin, ["pwexpiry"]) else: logger.info("pwexpiry already installed") if "pwdisable" not in installed: addPwDisablePlugin(acl, "pwdisable", "PwDisable Plugin") activatePluginInterfaces(portal, "pwdisable") for i in range(len(acl.plugins.listPluginIds(IChallengePlugin))): acl.plugins.movePluginsUp(IChallengePlugin, ["pwdisable"]) else: logger.info("pwdisable already installed") if not IS_PLONE_5: profile = "profile-collective.pwexpiry:plone4" ps.runAllImportStepsFromProfile(profile) if not IS_PLONE_5_2: profile = "profile-collective.pwexpiry:old_skins" ps.runAllImportStepsFromProfile(profile)
def ValidPasswordEntered(user, event): registry = queryUtility(IRegistry) if not registry: return # Now check if this user had his account locked if user.getProperty('account_locked', False): # It was locked, check how much time ago locked_date = user.getProperty('account_locked_date') disable_time = registry['collective.pwexpiry.disable_time'] portal = api.portal.get() current_time = portal.ZopeTime() delta = current_time.asdatetime() - locked_date.asdatetime() # We are checking in hours, so we divide in 3600 the elapsed seconds if (delta.seconds / 3600) >= disable_time: # Enough time has elapsed user.setMemberProperties({'account_locked': False, 'password_tries': 0}) msg = 'User {0} logged in after lock time; account is now unlocked' logger.info(msg.format(user)) else: user_disabled_time = disable_time - (delta.seconds / 3600) user.REQUEST.RESPONSE.setHeader('user_disabled', user.getId()) user.REQUEST.RESPONSE.setHeader('user_disabled_time', user_disabled_time) msg = 'User {0} tried to log in but account is locked for {1} hours' logger.warn(msg.format(user, user_disabled_time)) raise Unauthorized else: # This account has not been locked, reset current_tries counter if user.getProperty('password_tries', 0) > 0: user.setMemberProperties({'password_tries': 0})
def ValidPasswordEntered(user, event): registry = queryUtility(IRegistry) if not registry: return # Now check if this user had his account locked if user.getProperty("account_locked", False): # It was locked, check how much time ago locked_date = user.getProperty("account_locked_date") disable_time = registry["collective.pwexpiry.disable_time"] portal = api.portal.get() current_time = portal.ZopeTime() delta = current_time.asdatetime() - locked_date.asdatetime() # We are checking in hours, so we divide in 3600 the elapsed seconds if (delta.seconds / 3600) >= disable_time: # Enough time has elapsed user.setMemberProperties({ "account_locked": False, "password_tries": 0 }) msg = "User {0} logged in after lock time; account is now unlocked" logger.info(msg.format(user)) else: user_disabled_time = disable_time - (delta.seconds / 3600) user.REQUEST.RESPONSE.setHeader("user_disabled", user.getId()) user.REQUEST.RESPONSE.setHeader("user_disabled_time", user_disabled_time) msg = ( "User {0} tried to log in but account is locked for {1} hours") logger.warn(msg.format(user, user_disabled_time)) raise Unauthorized else: # This account has not been locked, reset current_tries counter if user.getProperty("password_tries", 0) > 0: user.setMemberProperties({"password_tries": 0})
validators = getAdapters((self,), ICustomPasswordValidator) for name, validator in validators: result = validator.validate(password, data) if result: return result original = original_testPasswordValidity(self, password, confirm) if original: return original return None RegistrationTool.testPasswordValidity = extended_testPasswordValidity logger.info( "Patching Products.CMFDefault.RegistrationTool.testPasswordValidity" ) if not IS_PLONE_5: # XXX: according to the comment below, this may be unnecessary from plone.app.users.browser.register import BaseRegistrationForm from Products.CMFCore.utils import getToolByName from zope.app.form.interfaces import WidgetInputError original_validate_registration = BaseRegistrationForm.validate_registration def extended_validate_registration(self, action, data): """Patching the standard Plone's validate_registration method to add validating the password given in the registration process against the testPasswordValidity method.