Enter Password in C

后端 未结 5 1783
梦毁少年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:51

    The function that you are looking for is: getpass(). You will note, though, that it is marked as "LEGACY". Although it isn't going to go anywhere, the function doesn't allow the size of the input buffer to be specified, which makes it not a very good interface. As Jefromi has noted, the glibc manual provides portable example code for implementing getpass from scratch in a way that allows an arbitrary input size (and isn't LEGACY).

提交回复
热议问题