从stdin读取密码(Read password from stdin)

编程入门 行业动态 更新时间:2024-10-28 10:24:41
从stdin读取密码(Read password from stdin)

场景:交互式CLI Python程序,需要一个密码。 这也意味着没有GUI解决方案可能。

在bash中,我可以在屏幕上重新提示密码读取密码

read -s

Python有什么类似的东西吗? 也就是说,

password = raw_input('Password: ', dont_print_statement_back_to_screen)

替代方法:使用'*'替换输入的字符,然后再发送回屏幕(又称浏览器样式)。

Scenario: An interactive CLI Python program, that is in need for a password. That means also, there's no GUI solution possible.

In bash I could get a password read in without re-prompting it on screen via

read -s

Is there something similar for Python? I.e.,

password = raw_input('Password: ', dont_print_statement_back_to_screen)

Alternative: Replace the typed characters with '*' before sending them back to screen (aka browser' style).

最满意答案

>>> import getpass >>> pw = getpass.getpass() >>> import getpass >>> pw = getpass.getpass()

更多推荐

本文发布于:2023-04-27 13:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327068.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码   stdin   password   Read

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!