從標準輸入讀取密碼 - Read password from stdin

問題:

Scenario: An interactive CLI Python program, that is in need for a password. 場景:一個交互式CLI Python程序,需要密碼。 That means also, there's no GUI solution possible. 這也意味着不可能有GUI解決方案。

In bash I could get a password read in without re-prompting it on screen via 在bash中,我可以讀取密碼而無需通過以下方式在屏幕上重新提示

read -s

Is there something similar for Python? Python有類似的東西嗎? Ie,

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). 替代方法:將鍵入的字符替換爲“ *”,然後再將其發送回屏幕(又稱瀏覽器樣式)。


解決方案:

參考一: https://en.stackoom.com/question/7OJE
參考二: https://stackoom.com/question/7OJE
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章