Save a set of authentication credentials.

        The credentials are used to login a socket whenever one is created.
        If `connect` is True, verify the credentials on the server first.
518403
def _cache_credentials(self, source, credentials, connect=False):
        
        # Don't let other threads affect this call's data.
        all_credentials = self.__all_credentials.copy()

        if source in all_credentials:
            # Nothing to do if we already have these credentials.
            if credentials == all_credentials[source]:
                return
            raise OperationFailure('Another user is already authenticated '
                                   'to this database. You must logout first.')

        if connect:
            server = self._get_topology().select_server(
                writable_preferred_server_selector)

            # get_socket() logs out of the database if logged in with old
            # credentials, and logs in with new ones.
            with server.get_socket(all_credentials) as sock_info:
                sock_info.authenticate(credentials)

        # If several threads run _cache_credentials at once, last one wins.
        self.__all_credentials[source] = credentials
1214526
def add_credential(self, url, username, password):
        
        cur = self.conn.cursor()

        cur.execute("SELECT * FROM credentials WHERE LOWER(username)=LOWER(?) AND password=?", [url, username, password])
        results = cur.fetchall()

        if not len(results):
            cur.execute("INSERT INTO credentials (username, password) VALUES (?,?)", [username, password] )

        cur.close()
976720
async def authenticate(self, username: str, password: str) -> None:
        """"""
        self._credentials = {
            'username': username,
            'password': password,
        }

        await self._get_security_token()
1074406
def set_auth_credentials(username, password):
    
    global _credentials, _dirty

    LOGGER.debug('Setting authentication credentials')
    _credentials = username, password
    _dirty = True
1344557
def save_credentials(self, profile):
        
        filename = profile_path(S3_PROFILE_ID, profile)
        creds = {
            "access_key": self.access_key,
            "secret_key": self.secret_key
        }
        dump_to_json(filename, creds)
881096
function authenticateLiveConnections(self, args, cb) {
    // Get the current viable connections
    var connections = self.allConnections();
    // Allow nothing else to use the connections while we authenticate them
    self.availableConnections = [];
    self.inUseConnections = [];
    self.connectingConnections = [];

    var connectionsCount = connections.length;
    var error = null;
    // No connections available, return
    if (connectionsCount === 0) {
      self.authenticating = false;
      return callback(null);
    }

    // Authenticate the connections
    for (var i = 0; i < connections.length; i++) {
      authenticate(self, args, connections[i], function(err, result) {
        connectionsCount = connectionsCount - 1;

        // Store the error
        if (err) error = err;

        // Processed all connections
        if (connectionsCount === 0) {
          // Auth finished
          self.authenticating = false;
          // Add the connections back to available connections
          self.availableConnections = self.availableConnections.concat(connections);
          // We had an error, return it
          if (error) {
            // Log the error
            if (self.logger.isError()) {
              self.logger.error(
                f(
                  '[%s] failed to authenticate against server %s:%s',
                  self.id,
                  self.options.host,
                  self.options.port
                )
              );
            }

            return cb(error, result);
          }
          cb(null, result);
        }
      });
    }
  }
446065
def _build_credentials_tuple(mech, source, user, passwd, extra):
    
    user = _unicode(user) if user is not None else None
    password = passwd if passwd is None else _unicode(passwd)
    if mech == 'GSSAPI':
        properties = extra.get('authmechanismproperties', {})
        service_name = properties.get('SERVICE_NAME', 'mongodb')
        canonicalize = properties.get('CANONICALIZE_HOST_NAME', False)
        service_realm = properties.get('SERVICE_REALM')
        props = GSSAPIProperties(service_name=service_name,
                                 canonicalize_host_name=canonicalize,
                                 service_realm=service_realm)
        # Source is always $external.
        return MongoCredential(mech, '$external', user, password, props)
    elif mech == 'MONGODB-X509':
        # user can be None.
        return MongoCredential(mech, '$external', user, None, None)
    else:
        if passwd is None:
            raise ConfigurationError("A password is required.")
        return MongoCredential(mech, source, user, password, None)
1227110
public Credentials userSignUp(Credentials credentials) throws DAOException{
        if (getUserByEmail(dao,credentials.getEmailAddress())!=null){
            throw new DAOException(HttpStatus.SC_CONFLICT,"User Already Exists");
        }
        ServerCredentials toSave = new ServerCredentials(credentials);

        toSave.decryptPassword(keyManager.getPrivateKey()); //decrypt the password
        String de = toSave.getPassword();
        String ha = BCrypt.hashpw(de, BCrypt.gensalt(10));

        toSave.setOwnerId(dao.count(Credentials.class.getName()) + 1);
        toSave.setPassword(ha); //hash the password for storage
        toSave.setAuthToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), toSave));
        toSave.setRecoveryToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), toSave));

        dao.save(toSave);

        return toSave;
    }
1034999
def set_credentials(self, username, password=None, region=None,
            tenant_id=None, authenticate=False):
        """"""
        self.username = username
        self.password = password
        self.tenant_id = tenant_id
        if region:
            self.region = region
        if authenticate:
            self.authenticate()
904761
def _get_credentials():
    '''
    
    '''
    ret = {
        'user': False,
        'passwd': False
    }

    # Loop through opts, grains, and pillar
    # Return the first acceptable configuration found
    for item in ret:
        for struct in [__opts__, __grains__, __pillar__]:
            # Look for the config key
            # Support old-style config format and new
            for config_key in __valid_configs[item]:
                value = salt.utils.data.traverse_dict_and_list(
                    struct,
                    config_key,
                    None)
                if value:
                    ret[item] = value
                    break
    return ret['user'], ret['passwd']
202875
def authenticate(params)
      credentials = Authenticate.configuration.user_model_class.credentials(params)
      Authenticate.configuration.user_model_class.authenticate(credentials)
    end
784861
def authenticate(self, username, password, db=None):
        
        if db is None:
            return self.get_connection().admin.authenticate(username, password)
        return self.get_connection()[db].authenticate(username, password)
1302835
def _build_credentials(self, nexus_switches):
        
        credentials = {}
        for switch_ip, attrs in nexus_switches.items():
            credentials[switch_ip] = (
                attrs[const.USERNAME], attrs[const.PASSWORD],
                attrs[const.HTTPS_VERIFY], attrs[const.HTTPS_CERT],
                None)
            if not attrs[const.HTTPS_VERIFY]:
                LOG.warning("HTTPS Certificate verification is "
                            "disabled. Your connection to Nexus "
                            "Switch %(ip)s is insecure.",
                            {'ip': switch_ip})
        return credentials
1245163
def insert_authentication_data(self, key):
        '''
        
        '''
        correct_authentication_data = self.calculate_authentication_data(key)
        self.authentication_data = correct_authentication_data
493089
def check_credentials(self):
        
        if self.username is None or self.password is None:
            raise DistlibException('username and password must be set')
        pm = HTTPPasswordMgr()
        _, netloc, _, _, _, _ = urlparse(self.url)
        pm.add_password(self.realm, netloc, self.username, self.password)
        self.password_handler = HTTPBasicAuthHandler(pm)
9689
def has_credentials_stored():
    

    try:
        with open(credentials_file, 'r') as f:
            token = f.readline().strip()
            id = f.readline().strip()

            return token
    except Exception, e:
        return False
408742
def store_password_in_keyring(credential_id, username, password=None):
    '''
    
    '''
    try:
        # pylint: disable=import-error
        import keyring
        import keyring.errors
        # pylint: enable=import-error
        if password is None:
            prompt = 'Please enter password for {0}: '.format(credential_id)
            try:
                password = getpass.getpass(prompt)
            except EOFError:
                password = None

            if not password:
                # WE should raise something else here to be able to use this
                # as/from an API
                raise RuntimeError('Invalid password provided.')

        try:
            _save_password_in_keyring(credential_id, username, password)
        except keyring.errors.PasswordSetError as exc:
            log.debug('Problem saving password in the keyring: %s', exc)
    except ImportError:
        log.error('Tried to store password in keyring, but no keyring module is installed')
        return False