我想允许用户使用命令行界面输入密码.但我不想在屏幕上显示此密码(或显示****").
I want to allow users to enter password using command-line interface. but I don't want to display this password on screen (or display "****").
如何在C中做到这一点?谢谢.
How to do it in C? Thanks.
更新:
我只在 Linux 上工作.所以我实际上并不关心 Win 或其他系统.我尝试了 Lucas 的解决方案,效果很好.不过,我还有一个问题:
I'm working on Linux only. So I don't actually care about Win or other systems. I tried Lucas' solution and it worked fine. However, I still have another question:
如果这是单个进程&单线程应用,改变termios的设置会影响不同的终端?
If this is a single process & single thread app, changing setting of termios affects different terminals?
1 个进程 - 多线程,多进程 - 多线程怎么样?
How about 1 process - multi threads, multi processes - multi threads?
非常感谢.
推荐答案如果您的系统提供,getpass 是一个选项:
If your system provides it, getpass is an option:
#include <unistd.h> /* ... */ char *password = getpass("Password: ");这不会在输入字符时显示任何内容.
This will not display anything as characters are typed.
更多推荐
C命令行密码输入
发布评论