zoukankan      html  css  js  c++  java
  • linux下输入密码不回显

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

    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
    ",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

  • 相关阅读:
    django学习笔记(一)
    Python之函数进阶
    Python之函数初识
    Python之文件操作
    基础补充
    字典
    神奇的列表
    万能的字符串
    Python基础(二)
    使用paramiko进行ssh连接
  • 原文地址:https://www.cnblogs.com/kingos/p/4512900.html
Copyright © 2011-2022 走看看