Decorator to prompt for user name and password. Useful for data dumps,
        etc.  That you don't want to be public.
169975
def requires_auth(self, func):
        '''
        
        '''
        @wraps(func)
        def decorated(*args, **kwargs):
            ''' Wrapper '''
            auth = request.authorization
            if not auth or not self.check_auth(auth.username, auth.password):
                return self.authenticate()
            return func(*args, **kwargs)
        return decorated
557406
def auth(username, password):
    
    def middleware(conn):
        conn.login(username, password)
    return middleware
1289815
def get_private_and_public(username, password_verifier, private, preset):
    """"""
    session = SRPServerSession(
        SRPContext(username, prime=preset[0], generator=preset[1]),
        hex_from_b64(password_verifier), private=private)

    click.secho('Server private: %s' % session.private_b64)
    click.secho('Server public: %s' % session.public_b64)
1106970
function auth (username, password, callback) {
    return relax({
      method: 'POST',
      db: '_session',
      form: {
        name: username,
        password: password
      }
    }, callback)
  }
393252
def del_password(name, root=None):
    '''
    
    '''
    cmd = ['passwd']
    if root is not None:
        cmd.extend(('-R', root))
    cmd.extend(('-d', name))

    __salt__['cmd.run'](cmd, python_shell=False, output_loglevel='quiet')
    uinfo = info(name, root=root)
    return not uinfo['passwd'] and uinfo['name'] == name
1234691
def _whoami():
    # type: () -> Tuple[Text,Text]
    """"""
    username = getuser()
    try:
        if onWindows():
            get_user_name = ctypes.windll.secur32.GetUserNameExW  # type: ignore
            size = ctypes.pointer(ctypes.c_ulong(0))
            get_user_name(3, None, size)

            name_buffer = ctypes.create_unicode_buffer(size.contents.value)
            get_user_name(3, name_buffer, size)
            fullname = str(name_buffer.value)
        else:
            fullname = pwd.getpwuid(os.getuid())[4].split(',')[0]
    except (KeyError, IndexError):
        fullname = username

    return (username, fullname)
525234
def present(name, password, permission):
    '''
    
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    users = __salt__['drac.list_users']()

    if __opts__['test']:
        if name in users:
            ret['comment'] = '`{0}` already exists'.format(name)
        else:
            ret['comment'] = '`{0}` will be created'.format(name)
            ret['changes'] = {name: 'will be created'}

        return ret

    if name in users:
        ret['comment'] = '`{0}` already exists'.format(name)
    else:
        if __salt__['drac.create_user'](name, password, permission, users):
            ret['comment'] = '`{0}` user created'.format(name)
            ret['changes'] = {name: 'new user created'}
        else:
            ret['comment'] = 'Unable to create user'
            ret['result'] = False

    return ret
249228
def ask_for_password(cls, ui, prompt='Provide your password:', **options):
        
        # optionally set title, that may be used by some helpers like zenity
        return cls.get_appropriate_helper(ui).ask_for_password(prompt,
                                                               title=options.get('title', prompt))
431129
def sanitize_loginurl (self):
        """"""
        url = self["loginurl"]
        disable = False
        if not self["loginpasswordfield"]:
            log.warn(LOG_CHECK,
            _("no CGI password fieldname given for login URL."))
            disable = True
        if not self["loginuserfield"]:
            log.warn(LOG_CHECK,
            _("no CGI user fieldname given for login URL."))
            disable = True
        if self.get_user_password(url) == (None, None):
            log.warn(LOG_CHECK,
            _("no user/password authentication data found for login URL."))
            disable = True
        if not url.lower().startswith(("http:", "https:")):
            log.warn(LOG_CHECK, _("login URL is not a HTTP URL."))
            disable = True
        urlparts = urlparse.urlsplit(url)
        if not urlparts[0] or not urlparts[1] or not urlparts[2]:
            log.warn(LOG_CHECK, _("login URL is incomplete."))
            disable = True
        if disable:
            log.warn(LOG_CHECK,
              _("disabling login URL %(url)s.") % {"url": url})
            self["loginurl"] = None
125859
def login_required(function=None, message=None, login_url=None):
    
    actual_decorator = user_passes_test(
        lambda u: u.is_authenticated(),
        message=message,
        login_url=login_url
    )

    if function:
        return actual_decorator(function)
    return actual_decorator
1315143
def get_input(*args, secret=False, required=False, blank=False, **kwargs):
    

    while True:
        if secret:
            value = getpass.getpass(*args, **kwargs)
        else:
            value = input(*args, **kwargs)

        if blank:
            value = value if value else None

        if not required or value:
            break

    return value
35426
def auth(username, password):
    '''
    
    '''
    django_auth_path = __opts__['django_auth_path']
    if django_auth_path not in sys.path:
        sys.path.append(django_auth_path)
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', __opts__['django_auth_settings'])

    __django_auth_setup()

    if not is_connection_usable():
        connection.close()

    import django.contrib.auth  # pylint: disable=import-error,3rd-party-module-not-gated
    user = django.contrib.auth.authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            log.debug('Django authentication successful')
            return True
        else:
            log.debug('Django authentication: the password is valid but the account is disabled.')
    else:
        log.debug('Django authentication failed.')

    return False
1180460
def set_user_password(environment, parameter, password):
    
    username = '%s:%s' % (environment, parameter)
    return password_set(username, password)
630260
def passwordbox(msg="Enter your password."
    , title=" "
    , default=""
    , image=None
    , root=None
    ):
    
    return __fillablebox(msg, title, default, mask="*",image=image,root=root)
759307
def _get_auth(username, password):
    '''
    
    '''
    if username and password:
        return requests.auth.HTTPBasicAuth(username, password)
    else:
        return None
809384
def prompt_pass(name, default=None):
    

    prompt = name + (default and ' [%s]' % default or '')
    prompt += name.endswith('?') and ' ' or ': '
    while True:
        rv = getpass.getpass(prompt)
        if rv:
            return rv
        if default is not None:
            return default
1097229
def _auth(self, username, password) :
        
        self.user_credentials = self.call('auth', {'username': username, 'password': password})
        
        if 'error' in self.user_credentials:
            raise T411Exception('Error while fetching authentication token: %s'\
                    % self.user_credentials['error'])
        # Create or update user file
        user_data = dumps({'uid': '%s' % self.user_credentials['uid'], 'token': '%s' % self.user_credentials['token']})
        with open(USER_CREDENTIALS_FILE, 'w') as user_cred_file:
            user_cred_file.write(user_data)
        return True