码迷,mamicode.com
首页 > 系统相关 > 详细

linux下输入密码不回显

时间:2015-05-18 20:21:28      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

这几天在做一个登陆的程序,需要将输入的密码屏蔽掉,自己百度,找到了两种方法,先贴下第一种方法,

1 #include<stdio.h>
2 #include<unistd.h>
3 int main()
4 {
5     char *password;
6     password=getpass("input passwd");
7     printf("password is %s\n",password);
8     return 0;
9 }

getpass函数不会将接受到的字符显示,此函数需要包含头文件unistd.h

下面介绍第二种方法(这种方法我没有使用,大家可以试下)

1 void psswd()
2 {
3       initscr();                                 //开启curses模式
4       noecho();                             //echo() and noecho(),默认输入显示在终端;
5        endwin();                            //关闭curses模式
6 }

这种方法需要包含头文件curses.h,有些电脑上面可能没有这个头文件需要安装,我用的是sudo apt-get install libncurses5-dev 这条指令,然后程序在gcc的时候,需要链接上该头文件,如 gcc test.c -o test -lcurses,OK

linux下输入密码不回显

标签:

原文地址:http://www.cnblogs.com/kingos/p/4512900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!