用C输入密码 [英] Enter Password in C

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

问题描述

我知道,这是不可能的呼应*当你在标准的ANSI C.类型,但有一个人,而在控制台输入自己的密码不显示任何一种方式。我的意思是像在Unix / Linux终端sudo的提示。就像如果你键入命令:须藤CP的/ etc / somefile〜/ somedir 。您通常会提示输入根口令。而当你键入它的终端无显示。就是这种效果可以用C?如果是,怎么了?

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 console. What I mean is like the sudo prompts in a Unix/Linux terminal. Like if you type in the command: sudo cp /etc/somefile ~/somedir. You are usually prompted for the root password. And while you type it in, the terminal displays nothing. Is this effect possible in C? If it is, how?

推荐答案

这是你正在寻找的功能是:的将getpass()。你会注意到,虽然,它被标记为遗产。虽然不打算去任何地方,该函数不会允许指定的输入缓冲器的大小,这使得它不是一个很好的接口。正如Jefromi指出,glibc的手册提供移植的例子code实现从头将getpass的方式,允许任意输入大小(并且不是LEGACY)。

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).

这篇关于用C输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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