def __call__(self, form, field): pwd = field.data valid, message = check_password_strength( pwd, self.min_len, self.max_len, self.uppercase, self.lowercase, self.numeric, self.special, self.message) if not valid: raise ValidationError(message)
def __call__(self, form, field): pwd = field.data valid, message = check_password_strength(pwd, self.min_len, self.max_len, self.uppercase, self.lowercase, self.numeric, self.special, self.message) if not valid: raise ValidationError(message)
def create_users(self, user_repo, **form_data): """Create users from a remote source using an importer object and avoiding the creation of repeated users""" from pybossa.view.account import create_account n = 0 failcount = 0 importer = self._create_importer_for(**form_data) failed_user_imports = [] for user_data in importer.users(): try: found = user_repo.search_by_email( email_addr=user_data['email_addr'].lower()) if not found: password = user_data['password'] is_password_valid, message = check_password_strength( password) if not is_password_valid: failed_user_imports.append(user_data['fullname']) failcount += 1 else: project_slugs = user_data['project_slugs'].split() create_account(user_data, project_slugs=project_slugs) n += 1 except Exception: current_app.logger.exception('Error in create_user') if n > 0: msg = str(n) + " " + gettext( 'new users were imported successfully.') else: msg = gettext('It looks like there were no new users created.') if failcount > 0: msg += str(failcount) + gettext( ' user(s) could not be imported due to weak password.') current_app.logger.error( 'Failed to import users due to password mismatch: {0}'.format( ",".join(failed_user_imports))) return msg
def test_valid_strong_password_works(self): password = '******' valid, _ = util.check_password_strength(password=password) assert valid
def test_strong_password_min_length(self): password = '******' valid, _ = util.check_password_strength(password=password) assert not valid
def test_strong_password_missing_lowercase(self): password = '******' valid, _ = util.check_password_strength(password=password) assert not valid
def test_strong_password_missing_special_char(self): password = '******' valid, _ = util.check_password_strength(password=password) assert not valid