Home >Backend Development >Python Tutorial >Introduction to how Python uses the getpass library to read passwords

Introduction to how Python uses the getpass library to read passwords

黄舟
黄舟Original
2017-10-10 10:48:461954browse

This article mainly introduces the example of using Python to read passwords using the getpass library. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look.

I have such an experience. The server hangs up and requires engineers to maintain it. For safety reasons, when engineers perform core operations, they directly turn off the monitor to operate. After completion, turn on the monitor again. , carry out the finishing work...

Password

This experience tells us:

  1. For Security, core operations are invisible

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

In Linux In the system, when entering a password at the terminal, the number of password digits is not displayed (no echo is displayed)

In the early years, there were only a few computers, and there would be one person operating the computer, and a group of people watching behind him. When people see the number of digits entered in the password, it will cause security problems, so the problem is solved by not echoing the password (the password is not echoed, and if you make a few fake movements with your fingers, it will be difficult for others to see your password)

Here we use a simple python library to simulate this operation

animation_no echo login

For convenience To learn, put the comments in the source code:

Source code


# getpass是一个非常简单的Python标准库
# 主要包含两个函数:
# 函数1:getuser //从系统变量中自动获取用户名
# 函数2:getpass // 类似于input, 但不会将我们输入的字符显示在命令行中(不回显)

from __future__ import print_function

import getpass


# 自动读取当前用户的名称
user = getpass.getuser()

print("尊敬的",user)

# 以不回显的方式,读取用户的输入
passwd = getpass.getpass("请输入您的密码:")

print("------------->华丽的分割线<----------------")


print("您的密码为:", passwd)

The above is the detailed content of Introduction to how Python uses the getpass library to read passwords. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn