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:
For security, the core operation is not visible.
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)