Ensure that Username is unique. This validator may NOT be customized.
178653
def unique_username_validator(form, field):
    
    user_manager =  current_app.user_manager
    if not user_manager.db_manager.username_is_available(field.data):
        raise ValidationError(_('This Username is already in use. Please try another one.'))
937440
public function validation()
    {

        $validator = new Validation();

        $validator->add('name', new PresenceOf([
            'message' => 'User type name must be supplied'
        ]));

        $validator->add('name', new Uniqueness([
            'message' => 'Sorry, the user type already exists'
        ]));

        return $this->validate($validator);
    }
1373070
def validate_identifier(self, field):
        """"""
        if field.data:
            field.data = field.data.lower()
            if Community.get(field.data, with_deleted=True):
                raise validators.ValidationError(
                    _('The identifier already exists. '
                      'Please choose a different one.'))
648154
def _validate_unique(self, unique, field, value):
        
        if unique:
            root_key = self.schema_path[0]
            data = (doc[field] for doc in self.root_document[root_key])
            for key, count in collections.Counter(data).items():
                if count > 1:
                    msg = "'{}' is not unique".format(key)
                    self._error(field, msg)
1071883
def validate(self):
        """"""
        if self.GROUP_ATTRIBUTES and self.GROUPNAME_FIELD not in self.GROUP_ATTRIBUTES.values():
            raise ImproperlyConfigured("LDAP_SYNC_GROUP_ATTRIBUTES must contain '%s'" % self.GROUPNAME_FIELD)

        if not self.model._meta.get_field(self.USERNAME_FIELD).unique:
            raise ImproperlyConfigured("LDAP_SYNC_USERNAME_FIELD '%s' must be unique" % self.USERNAME_FIELD)

        if self.USER_ATTRIBUTES and self.USERNAME_FIELD not in self.USER_ATTRIBUTES.values():
            raise ImproperlyConfigured("LDAP_SYNC_USER_ATTRIBUTES must contain '%s'" % self.USERNAME_FIELD)
25501
def ensure_unique(qs, field_name, value, exclude_id=None):
    
    orig = value
    if not value:
        value = "None"
    for x in itertools.count(1):
        if not qs.exclude(id=exclude_id).filter(**{field_name: value}).exists():
            break
        if orig:
            value = '%s-%d' % (orig, x)
        else:
            value = '%d' % x

    return value
240182
def username_validator(self, form, field):
        
        username = field.data
        if len(username) < 3:
            raise ValidationError(
                _('Username must be at least 3 characters long'))
        valid_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._'
        chars = list(username)
        for char in chars:
            if char not in valid_chars:
                raise ValidationError(
                    _("Username may only contain letters, numbers, '-', '.' and '_'"))
970769
def validate_username(form, field):
        """"""
        try:
            validate_username(field.data)
        except ValueError as e:
            raise ValidationError(e)

        try:
            user_profile = UserProfile.get_by_username(field.data)
            if current_userprofile.is_anonymous or \
                    (current_userprofile.user_id != user_profile.user_id and
                     field.data != current_userprofile.username):
                # NOTE: Form validation error.
                raise ValidationError(_('Username already exists.'))
        except NoResultFound:
            return
732438
def clean_username(self, username, shallow=False):
        
        for validator in app_settings.USERNAME_VALIDATORS:
            validator(username)

        # TODO: Add regexp support to USERNAME_BLACKLIST
        username_blacklist_lower = [ub.lower()
                                    for ub in app_settings.USERNAME_BLACKLIST]
        if username.lower() in username_blacklist_lower:
            raise forms.ValidationError(
                self.error_messages['username_blacklisted'])
        # Skipping database lookups when shallow is True, needed for unique
        # username generation.
        if not shallow:
            from .utils import filter_users_by_username
            if filter_users_by_username(username).exists():
                user_model = get_user_model()
                username_field = app_settings.USER_MODEL_USERNAME_FIELD
                error_message = user_model._meta.get_field(
                    username_field).error_messages.get('unique')
                if not error_message:
                    error_message = self.error_messages['username_taken']
                raise forms.ValidationError(
                    error_message,
                    params={
                        'model_name': user_model.__name__,
                        'field_label': username_field,
                    }
                )
        return username
490743
def valid_username(user):
    '''
    
    '''
    if not isinstance(user, six.string_types):
        return False

    if len(user) > 32:
        return False

    return VALID_USERNAME.match(user) is not None
1267470
def clean(self):
        
        if self.user:
            self.username = self.user.username
        elif not self.username:
            raise ValidationError({
                'username': _NOT_BLANK_MESSAGE,
                'user': _NOT_BLANK_MESSAGE
            })
1372
def valid_user
      if (self.username.blank? || self.password_digest.blank?) &&
          (self.oauth_provider.blank? || self.oauth_uid.blank?)
        errors.add(:username, " and password OR oauth must be specified")
      end
    end
802031
def username(self, value):
        """"""
        if isinstance(value, str):
            self._username = value
            self._handler = None
711882
def clean_username(self):
        
        username = self.cleaned_data.get('username').split('@')[0]
        if not username:
            raise forms.ValidationError(_('Invalid username provided'))
        return username
1004967
public function username($username)
    {
        $app = Application::getFacadeApplication();
        $validator = $app->make('validator/user/name');
        foreach ($validator->getValidators() as $handle => $validator) {
            if ($handle !== 'unique_username') {
                if (!$validator->isValid($username)) {
                    return false;
                }
            }
        }

        return true;
    }
1328621
def is_valid(self):
        ''' 
        '''
        if not super(AddUserForm, self).is_valid():
            return False
        first_name = self.cleaned_data['first_name']
        last_name = self.cleaned_data['last_name']
        if User.objects.filter(first_name=first_name, last_name=last_name).count():
            non_field_error = "A profile for {0} {1} already exists with username {2}." \
              .format(first_name, last_name,
                      User.objects.get(first_name=first_name, last_name=last_name).username)
            form_add_error(self, '__all__', non_field_error)
            return False
        if self.cleaned_data['user_password'] != self.cleaned_data['confirm_password']:
            form_add_error(self, 'user_password', "Passwords don't match.")
            form_add_error(self, 'confirm_password', "Passwords don't match.")
            return False
        return True
874455
def validate_authentication(self, username, password, handler):
        
        user = authenticate(
            **{self.username_field: username, 'password': password}
        )
        account = self.get_account(username)
        if not (user and account):
            raise AuthenticationFailed("Authentication failed.")