Python keyring 模块,set_password() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用keyring.set_password()

项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def dump_profile(profile):
    '''?????????.

    ???????????????, ??????????, ???keyring??
    ???.
    ???????, ???????.
    '''
    profile = profile.copy()
    path = os.path.join(Config.CONF_DIR, profile['username'])
    if profile['remember-password'] and profile['password']:
        for i in range(RETRIES):
            try:
                keyring.set_password(Config.DBUS_APP_NAME, profile['username'],
                                     profile['password'])
                break
            except dbus.exceptions.DBusException:
                logger.error(traceback.format_exc())
    profile['password'] = ''
    with open(path, 'w') as fh:
        json.dump(profile, fh)
项目:jira_reporting_scripts    作者:andrew-hamlin-sp    | 项目源码 | 文件源码
def get_credentials(username, password):
    if not username:
        username = getpass.getuser()

    _needs_storage = True

    if not password:
        # retrieve password from system storage
        if keyring.get_keyring():
            password = keyring.get_password(KEYRING_NAME, username)
            if password:
                _needs_storage = False

    if not password:
        password = getpass.getpass('Enter password for {}: '.format(username))

    if _needs_storage and keyring.get_keyring():
        try:
            keyring.set_password(KEYRING_NAME, username, password)
        except keyring.errors.PasswordSetError as err:
            Log.error(err)

    return username, password
项目:netcrawl    作者:Wyko    | 项目源码 | 文件源码
def _get_fernet_key(app_name= 'netcrawl',
                    username= 'netcrawl'):
    proc= 'manage._get_fernet_key'

    # Retrieve the encryption key from storage or generate one
    key= keyring.get_password(app_name, username)
    if key is None:
        log('Creating encryption key', v= logging.N, proc= proc)
        key = Fernet.generate_key()
        keyring.set_password(app_name, username, str(key, encoding='utf-8'))
    else:
        key= bytes(key, encoding='utf-8')

    # Create a Fernet key from the base key
    return Fernet(key)
    del(key)
项目:zeex    作者:zbarge    | 项目源码 | 文件源码
def set_password(self, service_name, username, password, **kwargs):
        keyring.set_password(service_name, username, password)
        self.get_password(service_name, username, **kwargs)
项目:config-sesame    作者:1and1    | 项目源码 | 文件源码
def login(ctx):
    """Set or change Vault login credentials in your keyring."""
    if not keyring:
        raise UsageError("'keyring' support is not available, please read"
            " 'https://config-sesame.readthedocs.io/en/latest/deploy.html'!", ctx=ctx)
    url, user, token, _ = vault.default_credentials()
    if not url:
        raise UsageError("You MUST provide a VAULT_ADDR!", ctx=ctx)
    if token:
        click.secho("WARN: You have a VAULT_TOKEN variable in your environment,"
                    " which will override any keyring credentials!",
                    fg='yellow', bg='black', bold=True, reverse=True)

    click.echo("Please enter credentials for storing in {}.{}..."
               .format(keyring.get_keyring().__class__.__module__, keyring.get_keyring().__class__.__name__))
    access = security.Credentials(url)
    user, token = access.auth_pair(force_console=True)  # Prompt for new password
    keyring.set_password(url, user, token)
    click.echo("Updated {}'s password (token) for {}".format(user, url))
项目:cbas    作者:ImmobilienScout24    | 项目源码 | 文件源码
def keyring_get_password(username):
    keyring_impl = keyring.get_keyring()
    verbose("Note: will use the backend: '{0}'".format(keyring_impl))
    password = keyring.get_password('cbas', username)
    if not password:
        info("No password found in keychain, please enter it now to store it.")
        password = prompt_get_password(username)
        keyring.set_password('cbas', username, password)
    return password
项目:oscars2016    作者:0x0ece    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:oscars2016    作者:0x0ece    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')
项目:glog-cli    作者:globocom    | 项目源码 | 文件源码
def store_password_in_keyring(host, username, password):
    keyring.set_password('glog_' + host, username, password)
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:office-interoperability-tools    作者:milossramek    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:office-interoperability-tools    作者:milossramek    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')
项目:github-reviewboard-sync    作者:Apptimize-OSS    | 项目源码 | 文件源码
def _get_password(system, username, refresh=False):
    system_store_name = 'sync-{0}'.format(system)
    password = None
    if not refresh:
        password = keyring.get_password(system_store_name, username)
    if password is None:
        password = getpass('{0} password for "{1}":'.format(system, username))
        keyring.set_password(system_store_name, username, password)
    return password
项目:competitive-cli    作者:GDGVIT    | 项目源码 | 文件源码
def insert(self, website, username, password):
        if [website, username] in self.data["accounts"].values():
            return

        new_index = self.number_of_accounts + 1

        self.account = new_index
        self.number_of_accounts += 1
        self.data["accounts"][new_index] = [website, username]
        keyring.set_password(website, username, password)
项目:competitive-cli    作者:GDGVIT    | 项目源码 | 文件源码
def update(self, key, password):
        key = str(key)
        if key not in self.data["accounts"]:
            print("Account with given index does not exist")
            return
        website, username = self.data["accounts"][key]
        keyring.delete_password(website, username)
        keyring.set_password(website, username, password)
        return
项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:modman    作者:haihala    | 项目源码 | 文件源码
def set_credentials(cred):
        assert isinstance(cred, Credentials)
        return keyring.set_password(APP_NAME, getuser(), "\n".join([cred.username, cred.password]))
项目:ozelot    作者:trycs    | 项目源码 | 文件源码
def store_password(params, password):
        """Store the password for a database connection using :mod:`keyring`

        Use the ``user`` field as the user name and ``<host>:<driver>`` as service name.

        Args:
            params (dict): database configuration, as defined in :mod:`ozelot.config`
            password (str): password to store
        """
        user_name = params['user']
        service_name = params['host'] + ':' + params['driver']
        keyring.set_password(service_name=service_name,
                             username=user_name,
                             password=password)
项目:imapautofiler    作者:dhellmann    | 项目源码 | 文件源码
def get_password(self):
        password = keyring.get_password(self.hostname, self.username)
        if not password:
            LOG.debug("No keyring password; getting one interactively")
            password = getpass.getpass(
                'Password for {} (will be stored in the system keyring):'
                .format(self.username)
            )
            keyring.set_password(self.hostname, self.username, password)

        return keyring.get_password(self.hostname, self.username)
项目:QCrash    作者:ColinDuquesnoy    | 项目源码 | 文件源码
def _store_credentials(self, username, password, remember, remember_pswd):
        if remember:
            self.qsettings().setValue('github/username', username)
        if remember_pswd:
            try:
                keyring.set_password('github', username, password)
            except RuntimeError:  # pragma: no cover
                _logger().warn('failed to save password in keyring, you '
                               'will be prompted for your credentials '
                               'next time you want to report an issue')
                remember_pswd = False
        self.qsettings().setValue(
            'github/remember_credentials', int(remember))
        self.qsettings().setValue(
            'github/remember_password', int(remember_pswd))
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def on_connection_panel_connection_changed(self, widget, host, port, password, image_dir):
        self._settings.set_string(Window.SETTING_HOST, host)
        self._settings.set_int(Window.SETTING_PORT, port)
        if use_keyring:
            if password:
                keyring.set_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME, password)
            else:
                if keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME):
                   keyring.delete_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME)
        self._settings.set_string(Window.SETTING_IMAGE_DIR, image_dir)
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def set_password(self, password):
        if password is None:
            password = ""
        self._password_entry.set_text(password)
项目:python-zunclient    作者:openstack    | 项目源码 | 文件源码
def save(self, auth_token, management_url, tenant_id):
        if not HAS_KEYRING or not self.args.os_cache:
            return
        if (auth_token == self.auth_token and
                management_url == self.management_url):
            # Nothing changed....
            return
        if not all([management_url, auth_token, tenant_id]):
            raise ValueError("Unable to save empty management url/auth token")
        value = "|".join([str(auth_token),
                          str(management_url),
                          str(tenant_id)])
        keyring.set_password("zunclient_auth", self._make_key(), value)
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')
项目:onedrived-dev    作者:xybu    | 项目源码 | 文件源码
def save_session(self, **save_session_kwargs):
        if self.SESSION_ARG_KEYNAME not in save_session_kwargs:
            raise ValueError('"%s" must be specified in save_session() argument.' % self.SESSION_ARG_KEYNAME)
        data = base64.b64encode(zlib.compress(pickle.dumps(self, self.PICKLE_PROTOCOL))).decode('utf-8')
        keyring.set_password(self.KEYRING_SERVICE_NAME, save_session_kwargs[self.SESSION_ARG_KEYNAME], data)
项目:driveboardapp    作者:nortd    | 项目源码 | 文件源码
def main():
    keyring.set_password("pyinstaller", "username", "password")
    keyring.get_password("pyinstaller", "username")
项目:kapsel    作者:conda    | 项目源码 | 文件源码
def set(env_prefix, variable, value):
    assert value is not None

    name = _make_username(env_prefix, variable)
    if not _use_fallback_keyring():
        try:
            keyring.set_password("anaconda", name, value)
            return
        except Exception as e:
            # keyring throws a bare "RuntimeError" if it has no working backend;
            # not sure what else it can throw.
            _onetime_keyring_complain_and_disable("Exception setting a password: " + str(e))

    # on either exception, or disabled
    _fake_in_memory_keyring[name] = value
项目:got    作者:mrozekma    | 项目源码 | 文件源码
def save(self):
        keyring.set_password(self.host_name, self.username, self.password)
项目:ecodash    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:ecodash    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:ecodash    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:ecodash    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def write(self, *args):
        """See ConfigParser.write().  Also writes secure items to keystore."""
        ConfigParser.write(self, *args)
        if self.keyring_available:
            for key, thing in self._unsaved.items():
                action = thing[0]
                value = thing[1]
                if action == 'set':
                    keyring.set_password(self.keyring_name, key, value)
                elif action == 'delete':
                    try:
                        keyring.delete_password(self.keyring_name, key)
                    except:
                        pass
        self._unsaved = {}
项目:aqua-monitor    作者:Deltares    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:aqua-monitor    作者:Deltares    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:SurfaceWaterTool    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_put(self, credentials):
        """Write Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())
项目:SurfaceWaterTool    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_delete(self):
        """Delete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        """
        keyring.set_password(self._service_name, self._user_name, '')
项目:SurfaceWaterTool    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:SurfaceWaterTool    作者:Servir-Mekong    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def locked_delete(self):
    """Delete Credentials file.

    Args:
      credentials: Credentials, the credentials to store.
    """
    keyring.set_password(self._service_name, self._user_name, '')