How Python uses the Getpass library to read passwords

Source: Internet
Author: User
This article mainly introduces Python to use the Getpass library to read the password example, small series feel very good, and now share to everyone, but also for everyone to do a reference. Let's take a look at it with a little knitting.

There is such an experience, the server hangs, please engineer maintenance, in order to safety, the engineer to carry out the core operation, the direct switch off the monitor to operate, after completion, then open the display, the finishing work ...

Password

This experience tells us:

    1. For security, the core operation is not visible.

    2. In some cases, the display can be ignored ...

In a Linux system, when a password is entered in the terminal, the number of passwords is not displayed (not echoed)

In the early years, the number of computers, there will be a person to operate the computer, behind a group of people watching, be seen to enter the number of passwords, will lead to security issues, so, the use of the way to solve the problem (password does not echo, your fingers do a few fake actions, others will be difficult to see your password)

Here we use a simple Python library to simulate this operation

No echo Login

For the convenience of learning, comments are placed in the source code:

Source


# Getpass is a very simple Python standard library # consisting mainly of two functions: # function 1:getuser//automatically get user name from System variable # function 2:getpass//similar to input, However, the characters we enter are not displayed on the command line (not echoed) from __future__ import Print_functionimport getpass# automatically reads the name of the current user users = Getpass.getuser () print ( "Respectable", user) # Read the user's input passwd = Getpass.getpass ("Please enter your password:") print ("-------------> Gorgeous split line <---------------" In a way that does not echo back -") Print (" Your password is: ", passwd) 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.