C命令行输入密码 [英] C command-line password input

查看:339
本文介绍了C命令行输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户使用命令行界面输入密码。但我不想在屏幕上显示此密码(或显示****)。

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上。所以我不真正关心赢或其他系统。我想卢卡斯的解决方案,它工作得很好。不过,我还有另一个问题:

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:


  1. 如果这是一个单一的过程和放大器;单线程应用程序,termios的不断变化的设置会影响不同的终端?

  1. 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命令行输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆