当前位置: 首页>>代码示例>>Python>>正文


Python getpass.getpass方法代码示例

本文整理汇总了Python中getpass.getpass方法的典型用法代码示例。如果您正苦于以下问题:Python getpass.getpass方法的具体用法?Python getpass.getpass怎么用?Python getpass.getpass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在getpass的用法示例。


在下文中一共展示了getpass.getpass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _GetPasswordGUI

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def _GetPasswordGUI(title='Password', text='Enter your password', hidden=True):
  """Application and platform specific GUI getpass.

  Args:
    title: string for title of window
    text: string for promp text
    hidden: bool whether to show user input
  Returns:
    password as string
  """
  pwprompt = cocoadialog.Standard_InputBox()
  if hidden:
    pwprompt.SetPasswordBox()
  pwprompt._title = title  # pylint: disable=protected-access
  pwprompt._informative_text = text  # pylint: disable=protected-access
  output = pwprompt.Show()
  password = output.split('\n')[1]
  return password 
开发者ID:google,项目名称:macops,代码行数:20,代码来源:getauth.py

示例2: _GetPasswordInteractively

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def _GetPasswordInteractively(prompt='Password: ', hidden=True,
                              input_fn=raw_input):
  """Application specific getpass.

  Args:
    prompt: string with the password prompt
    hidden: bool whether to show user input
    input_fn: function to get user input, used in testing
  Returns:
    password as string
  Raises:
    KeyboardInterrupt: User cancelled request with keyboard interrupt (Ctrl+C)
    EOFError: If password is empty
  """
  if hidden:
    password = getpass.getpass(prompt)
  else:
    password = input_fn(prompt)
  return password 
开发者ID:google,项目名称:macops,代码行数:21,代码来源:getauth.py

示例3: _get_key

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def _get_key():
    if this.key:
        return this.key

    secret = getpass.getpass()
    try:
        salt = config().get('Security', 'salt')
    except NoOptionError:
        salt = base64.urlsafe_b64encode(os.urandom(16))
        config().set('Security', 'salt', salt)

    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
        backend=default_backend()
    )
    this.key = base64.urlsafe_b64encode(kdf.derive(secret))
    return this.key 
开发者ID:rtshome,项目名称:pgrepup,代码行数:22,代码来源:crypt.py

示例4: password

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def password(ctx):
    """
    Change the router admin password.
    """
    url = ctx.obj['base_url'] + "/password/change"

    username = builtins.input("Username: ")
    while True:
        password = getpass.getpass("New password: ")
        confirm = getpass.getpass("Confirm password: ")

        if password == confirm:
            break
        else:
            print("Passwords do not match.")

    data = {
        "username": username,
        "password": password
    }
    router_request("POST", url, json=data) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:23,代码来源:device.py

示例5: set_password

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def set_password(ctx):
    """
    Change the local admin password.

    Set the password required by `pdtools node login` and the local
    web-based administration page.
    """
    username = builtins.input("Username: ")
    while True:
        password = getpass.getpass("New password: ")
        confirm = getpass.getpass("Confirm password: ")

        if password == confirm:
            break
        else:
            print("Passwords do not match.")

    click.echo("Next, if prompted, you should enter the current username and password.")
    client = ctx.obj['client']
    result = client.set_password(username, password)
    click.echo(util.format_result(result))
    return result 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:24,代码来源:node.py

示例6: get_input

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def get_input(*args, secret=False, required=False, blank=False, **kwargs):
    """
    secret: Don't show user input when they are typing.
    required: Keep prompting if the user enters an empty value.
    blank: turn all empty strings into None.
    """

    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 
开发者ID:MichaelAquilina,项目名称:S4,代码行数:22,代码来源:utils.py

示例7: __init__

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def __init__(self, *args, **kwargs):
        super(JiraPlugin, self).__init__(*args, **kwargs)
        self.store = KeyValueStore("jira.json")
        self.rooms = RoomContextStore(
            [JiraPlugin.TYPE_TRACK, JiraPlugin.TYPE_EXPAND]
        )

        if not self.store.has("url"):
            url = raw_input("JIRA URL: ").strip()
            self.store.set("url", url)

        if not self.store.has("user") or not self.store.has("pass"):
            user = raw_input("(%s) JIRA Username: " % self.store.get("url")).strip()
            pw = getpass.getpass("(%s) JIRA Password: " % self.store.get("url")).strip()
            self.store.set("user", user)
            self.store.set("pass", pw)

        self.auth = (self.store.get("user"), self.store.get("pass"))
        self.regex = re.compile(r"\b(([A-Za-z]+)-\d+)\b") 
开发者ID:matrix-org,项目名称:Matrix-NEB,代码行数:21,代码来源:jira.py

示例8: ask_password

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def ask_password(profile, interactive):
    """
    Prompt for profile password
    """
    if not PY3:
        profile = profile.encode(SYS_ENCODING)

    passmsg = "\nMaster Password for profile {0}: ".format(profile)

    if sys.stdin.isatty() and interactive:
        passwd = getpass(passmsg)

    else:
        # Ability to read the password from stdin (echo "pass" | ./firefox_...)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            passwd = sys.stdin.readline().rstrip("\n")
        else:
            LOG.warning("Master Password not provided, continuing with blank password")
            passwd = ""

    return py2_decode(passwd) 
开发者ID:unode,项目名称:firefox_decrypt,代码行数:23,代码来源:firefox_decrypt.py

示例9: _init_connect

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def _init_connect(self):
        """ Connect to the Telegram server and Authenticate. """
        sprint('Connecting to Telegram servers...')
        if not self.connect():
            sprint('Initial connection failed.')

        # Then, ensure we're authorized and have access
        if not self.is_user_authorized():
            sprint('First run. Sending code request...')
            self.send_code_request(self.settings.phone_num)
            self_user = None
            while self_user is None:
                code = input('Enter the code you just received: ')
                try:
                    self_user = self.sign_in(self.settings.phone_num, code)
                # Two-step verification may be enabled
                except SessionPasswordNeededError:
                    pw = getpass("Two step verification is enabled. "
                                 "Please enter your password: ")
                    self_user = self.sign_in(password=pw) 
开发者ID:Kosat,项目名称:telegram-messages-dump,代码行数:22,代码来源:telegram_dumper.py

示例10: get_input

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def get_input(message='', secure=False, lowercase=False, check_timer=True, non_locking_values=[]):
    """
        Get and return user input
    """

    try:
        if secure:
            input_ = getpass.getpass(lock_prefix() + message)
        else:
            input_ = input(message)

        if check_timer and input_ not in non_locking_values:
            check_then_set_autolock_timer()
        else:
            set_autolock_timer()

        # Ensure the input is lowercased if required
        if lowercase:
            input_ = input_.lower()
    except KeyboardInterrupt:
        return False
    except Exception:  # Other Exception
        return False

    return input_ 
开发者ID:gabfl,项目名称:vault,代码行数:27,代码来源:menu.py

示例11: GetCredentials

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def GetCredentials():
    global repoName
    global private
    global username
    global password

    if repoName == "":
        repoName = input("Enter a name for the GitHub repository: ")
    if private == "":
        private = input("Private GitHub repository (y/n): ")
    while private != False and private != True:
        if private == "y":
            private = True
        elif private == "n":
            private = False
        else:
            print("{}Invalid value.{}".format(Fore.YELLOW, Fore.WHITE))
            private = input("Private GitHub repository (y/n): ")
    if username == "":
        username = input("Enter your GitHub username: ")
    if username == "" or password == "":
        password = getpass.getpass("Enter your GitHub password: ")


# creates GitHub repo if credentials are valid 
开发者ID:jarodburchill,项目名称:project-automation,代码行数:27,代码来源:automate_project.py

示例12: buildDatabase

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def buildDatabase( databaseName ):

   username = raw_input( "Enter MySQL user name: " )
   password = getpass.getpass( "Enter user password: " )

   print "Creating database %s:" % databaseName

   # retrieve database description from file
   print "\tRetrieving database definition:",

   try:
      databaseDefinition = retrieveDatabaseDefinition( databaseName )
   except TypeError:
      sys.exit( "ERROR\nThe database definition in %s.def is invalid" % databaseName )
   else:
      print "DONE"

   # get a cursor for MySQL
   print "\tConnecting to MySQL:",
   try:
      cursor = MySQLdb.connect( user = username, passwd = password ).cursor()
   except MySQLdb.OperationalError, error:
      sys.exit( "ERROR\nCould not connect to MySQL (%s)" % error ) 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:25,代码来源:DBSetup.py

示例13: get_value

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def get_value(prompt, default=None, hidden=False):
    '''Displays the provided prompt and returns the input from the user. If the
    user hits Enter and there is a default value provided, the default is
    returned.
    '''
    _prompt = '%s : ' % prompt
    if default:
        _prompt = '%s [%s]: ' % (prompt, default)

    if hidden:
        ans = getpass(_prompt)
    else:
        ans = raw_input(_prompt)

    # If user hit Enter and there is a default value
    if not ans and default:
        ans = default
    return ans 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:20,代码来源:create.py

示例14: get_terminal

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def get_terminal(text="Password", confirm=False, allowedempty=False):
    import getpass

    while True:
        pw = getpass.getpass(text)
        if not pw and not allowedempty:
            print_message("Cannot be empty!", "error")
            continue
        else:
            if not confirm:
                break
            pwck = getpass.getpass("Confirm " + text)
            if pw == pwck:
                break
            else:
                print_message("Not matching!", "warning")
    return pw 
开发者ID:bitshares,项目名称:uptick,代码行数:19,代码来源:ui.py

示例15: interactive_login

# 需要导入模块: import getpass [as 别名]
# 或者: from getpass import getpass [as 别名]
def interactive_login(self, username: str) -> None:
        """Logs in and internally stores session, asking user for password interactively.

        :raises LoginRequiredException: when in quiet mode.
        :raises InvalidArgumentException: If the provided username does not exist.
        :raises ConnectionException: If connection to Instagram failed."""
        if self.context.quiet:
            raise LoginRequiredException("Quiet mode requires given password or valid session file.")
        try:
            password = None
            while password is None:
                password = getpass.getpass(prompt="Enter Instagram password for %s: " % username)
                try:
                    self.login(username, password)
                except BadCredentialsException as err:
                    print(err, file=sys.stderr)
                    password = None
        except TwoFactorAuthRequiredException:
            while True:
                try:
                    code = input("Enter 2FA verification code: ")
                    self.two_factor_login(code)
                    break
                except BadCredentialsException:
                    pass 
开发者ID:instaloader,项目名称:instaloader,代码行数:27,代码来源:instaloader.py


注:本文中的getpass.getpass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。