Enter Password in C

后端 未结 5 1795
梦毁少年i
梦毁少年i 2020-12-17 20:17

I am aware that it is not possible to echo the * while you type in standard ANSI C. But is there a way to display nothing while someone is typing their password in the conso

5条回答
  •  生来不讨喜
    2020-12-17 20:43

    The poor-man's method of doing this is to read user input character by character, and after each character is received print out a backspace character followed by *. The output is technically sent to the console, but it is immediately erased and overwritten by an asterisk (often before that frame is even drawn to the screen). Note that this is not really a secure method and has several security holes, but for low-tech low-security applications, it works.

提交回复
热议问题