linux回删密码,密码以*显示
2016-12-06 19:49
246 查看
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int my_getch()
{
struct termios oldt,newt;
int ch;
tcgetattr(STDIN_FILENO,&oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
int getpasswd(char * passwd, int size)
{
int c;
int n = 0;
do
{
c = my_getch();
if(c != '\n' && c != '\r' && c != 127)
{
passwd
= c;
printf("*");
n++;
}
else if((c != '\n' | c != '\r') && c == 127)
{
if(n > 0)
{
n--;
printf("\b \b");//输出退格一个空格!!!
}
}
}while(c != '\n' && c != '\r' && n < (size - 1));
passwd
= '\0';
return 0;
}
int main()
{
char passWord[20];
printf("输入密码:\n");
getpasswd(passWord,20);
printf("\n");
printf("密码是:%s\n",passWord);
}
#include <termios.h>
#include <unistd.h>
int my_getch()
{
struct termios oldt,newt;
int ch;
tcgetattr(STDIN_FILENO,&oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
int getpasswd(char * passwd, int size)
{
int c;
int n = 0;
do
{
c = my_getch();
if(c != '\n' && c != '\r' && c != 127)
{
passwd
= c;
printf("*");
n++;
}
else if((c != '\n' | c != '\r') && c == 127)
{
if(n > 0)
{
n--;
printf("\b \b");//输出退格一个空格!!!
}
}
}while(c != '\n' && c != '\r' && n < (size - 1));
passwd
= '\0';
return 0;
}
int main()
{
char passWord[20];
printf("输入密码:\n");
getpasswd(passWord,20);
printf("\n");
printf("密码是:%s\n",passWord);
}
相关文章推荐
- Linux终端下输入密码显示星号
- GNU Linux shell时不进行回显(输入密码时不显示的需求)
- Linux下C语言键盘输入密码时无回显(屏幕不显示字符)
- Linux下实现输入密码以星号显示
- 【linux】Putty 登陆密码显示慢
- linux环境下关于显示日期及修改密码的小练习
- linux密码输入显示*
- [Linux C]RedHat环境下密码显示问题
- linux在终端输入密码时显示星号的实现方法
- Linux下C语言键盘输入密码时无回显(屏幕不显示字符)
- Linux中完成输入密码显示*功能
- linux 的密码问题 ---不带显示的
- 如何在终端输入密码时显示星号 | Linux 中国
- 调整Linux控制台的显示属性
- 修复Linux下超级用户的密码
- Linux中文输入及显示
- Linux下jdk1.5的安装及中文显示问题解决方案
- 将linux密码存储到OpenLDAP里面=OpenLDAP Everywhere Revisited
- 修改TTF字体美化显示效果【原文转自:http://www.linuxfans.org/】
- 刚学linux写的一个显示菱形图案的shell程序