Check if a user is an ldapcherry administrator
        @str username: name of the user
        @rtype: bool, True if administrator, False otherwise
967412
def _is_admin(self, username):
        
        roles = self._get_roles(username)
        return self.roles.is_admin(roles['roles'])
839188
def is_auth(self):
        
        if self.user_id is None:
            self.user_id = self.session.get('user_id')
        return bool(self.user_id)
936341
def get_specific_user():
    '''
    
    '''
    user = get_user()
    if salt.utils.platform.is_windows():
        if _win_current_user_is_admin():
            return 'sudo_{0}'.format(user)
    else:
        env_vars = ('SUDO_USER',)
        if user == 'root':
            for evar in env_vars:
                if evar in os.environ:
                    return 'sudo_{0}'.format(os.environ[evar])
    return user
853870
def get_sudoers_entry(username=None, sudoers_entries=None):
    
    for entry in sudoers_entries:
        if entry.startswith(username):
            return entry.replace(username, '').strip()
200537
def auth(username, password):
    '''
    
    '''
    if not HAS_LDAP:
        log.error('LDAP authentication requires python-ldap module')
        return False

    bind = None

    # If bind credentials are configured, verify that we receive a valid bind
    if _config('binddn', mandatory=False) and _config('bindpw', mandatory=False):
        search_bind = _bind_for_search(anonymous=_config('anonymous', mandatory=False))

        # If username & password are not None, attempt to verify they are valid
        if search_bind and username and password:
            bind = _bind(username, password,
                         anonymous=_config('auth_by_group_membership_only', mandatory=False)
                         and _config('anonymous', mandatory=False))
    else:
        bind = _bind(username, password,
                     anonymous=_config('auth_by_group_membership_only', mandatory=False)
                     and _config('anonymous', mandatory=False))

    if bind:
        log.debug('LDAP authentication successful')
        return bind

    log.error('LDAP _bind authentication FAILED')
    return False
467628
def check_auth(self, username, password):
        '''  '''
        return username == self.queryname and password == self.querypw
590761
def user_exists(self, username):
        

        response = self._get(self.rest_url + "/user",
                             params={"username": username})

        if not response.ok:
            return None

        return True
297052
public boolean hasUser(String userName) {
        boolean result = false;
        for (User item : getUsersList()) {
            if (item.getName().equals(userName)) {
                result = true;
            }
        }
        return result;
    }
171163
def check_auth(username, password):
    
    return (username == settings.PRIVATE_INDEX_USERNAME and
            settings.PRIVATE_INDEX_PASSWORD and
            password == settings.PRIVATE_INDEX_PASSWORD)
555078
def _username():
    '''
    
    '''
    if pwd:
        username = pwd.getpwuid(os.getuid()).pw_name
    else:
        username = getpass.getuser()

    return username
1365427
def admin?
    is_admin = ( ENV['USER'] == 'root' )
    unless is_admin
      ext_admin = exec(:check_admin) do |op, results|
        if op == :reduce
          results.values.include?(true)
        else
          results ? true : false
        end
      end
    end
    is_admin || ext_admin ? true : false
  end
39827
def user_exists(self, name):
        """"""
        users = self.data['users']
        for user in users:
            if user['name'] == name:
                return True
        return False
943187
def is_admin_user(self):
        
        user = api.user.get_current()
        roles = user.getRoles()
        return "LabManager" in roles or "Manager" in roles
480585
def _win_user_token_is_admin(user_token):
    '''
    
    '''
    class SID_IDENTIFIER_AUTHORITY(ctypes.Structure):
        _fields_ = [
            ("byte0", ctypes.c_byte),
            ("byte1", ctypes.c_byte),
            ("byte2", ctypes.c_byte),
            ("byte3", ctypes.c_byte),
            ("byte4", ctypes.c_byte),
            ("byte5", ctypes.c_byte),
        ]
    nt_authority = SID_IDENTIFIER_AUTHORITY()
    nt_authority.byte5 = 5

    SECURITY_BUILTIN_DOMAIN_RID = 0x20
    DOMAIN_ALIAS_RID_ADMINS = 0x220
    administrators_group = ctypes.c_void_p()
    if ctypes.windll.advapi32.AllocateAndInitializeSid(
            ctypes.byref(nt_authority),
            2,
            SECURITY_BUILTIN_DOMAIN_RID,
            DOMAIN_ALIAS_RID_ADMINS,
            0, 0, 0, 0, 0, 0,
            ctypes.byref(administrators_group)) == 0:
        raise Exception("AllocateAndInitializeSid failed")

    try:
        is_admin = ctypes.wintypes.BOOL()
        if ctypes.windll.advapi32.CheckTokenMembership(
                user_token,
                administrators_group,
                ctypes.byref(is_admin)) == 0:
            raise Exception("CheckTokenMembership failed")
        return is_admin.value != 0

    finally:
        ctypes.windll.advapi32.FreeSid(administrators_group)
5101
def can_view(self, user):
        """"""
        return user.is_admin or self == user \
            or set(self.classes).intersection(user.admin_for)
152949
def get_by_username(cls, username):
        
        return cls.query.filter(
            UserProfile._username == username.lower()
        ).one()
1009306
def belongs_to_ldap_group?(username, groupname)
      return false if service.nil?
      group_filter = Net::LDAP::Filter.equals('cn', groupname)
      member_filter = Net::LDAP::Filter.equals('member', "cn=#{username},#{account_tree}")
      entry = service.search(base: tree,
                             filter: group_filter & member_filter,
                             attributes: ['cn'])
      entry.count > 0
    end