當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。