我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用keyring.set_password()。
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)
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
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)
def set_password(self, service_name, username, password, **kwargs): keyring.set_password(service_name, username, password) self.get_password(service_name, username, **kwargs)
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))
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
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())
def locked_delete(self): """Delete Credentials file. Args: credentials: Credentials, the credentials to store. """ keyring.set_password(self._service_name, self._user_name, '')
def store_password_in_keyring(host, username, password): keyring.set_password('glog_' + host, username, password)
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
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)
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
def set_credentials(cred): assert isinstance(cred, Credentials) return keyring.set_password(APP_NAME, getuser(), "\n".join([cred.username, cred.password]))
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)
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)
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))
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)
def set_password(self, password): if password is None: password = "" self._password_entry.set_text(password)
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)
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)
def main(): keyring.set_password("pyinstaller", "username", "password") keyring.get_password("pyinstaller", "username")
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
def save(self): keyring.set_password(self.host_name, self.username, self.password)
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 = {}