How to have password echoed as asterisks

后端 未结 2 415
我在风中等你
我在风中等你 2020-11-27 08:04

I am trying to figure out how to prompt for a password, and have the users input echoed back as asterisks (********)

So recently, I took on the project

2条回答
  •  情深已故
    2020-11-27 08:10

    I think this way is very simple and effective

    import sys
    import msvcrt
    
    passwor = ''
    while True:
        x = msvcrt.getch()
        if x == '\r':
            break
        sys.stdout.write('*')
        passwor +=x
    
    print '\n'+passwor
    

提交回复
热议问题