当前位置:首页 » 编程语言 » c语言getpass
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言getpass

发布时间: 2022-10-04 17:21:54

c语言中,用什么函数可以使输入的字符不显示在屏幕上

getpass()函数可以使输入的字符不现实在屏幕上。
#include
<conio.h>
int
main(void)
{
char
*password;
password
=
getpass("Input
a
password:");
cprintf("The
password
is:
%s\r\n",
password);
return
0;
}
你试一试这个

② linux系统下用C语言编了个下程序,不知道如何在输入密码时隐藏,只显示“*”,求大神们帮帮忙啊 !!!

函数名: getch
功 能: 从控制台无回显地取一个字符
用 法: int getch(void);

#include<conio.h>
#include<stdio.h>
intmain(void)
{
charp[50];
inti=-1;
do{
++i;
p[i]=getch();
putchar('*');

}while(p[i]!=13);//13为回车ascii
p[i+1]='';//最后添加字符串结尾
putchar(' ');
puts(p);
return0;
}

③ 怎样实现输入验证码呢要用C语言的

#include <stdio.h>
#include <string.h>
main()
{
char a[15],i=3;
do{
printf("Password:");
gets(a);
if(strcmp(a,"hello")==0) break;//这里请连到你的密码文件或者是连接到数据库验证,这里是 hello
}while(--i);
if(i==0) printf("Input errer 3 num.System close!\n");
else
{
//这里写入你密码正确要执行的代码
}
}

④ c 的函数getpass

getpass 函数名: getpass
功 能: 读一个口令
用 法: char *getpass(char *prompt);
程序例:
#include <conio.h>
int main(void)
{
char *password;
password = getpass("Input a password:");
cprintf("The password is: %s\r\n",
password);
return 0;
}

⑤ 悬赏100分 如何用c语言 写一个密码程序

clude "string.h"

//考虑到用数据库文件保存注册信息的话要使用access创建文件并且还要配置数据源,所以我的方法是采用将注册信息保存到文件
//下面是完整的程序:

//登陆检测函数
int login(char *name,char *password)
{
char info[10000];
char *p=info;
FILE *file=fopen("user","r");
int size;
if(file)
{
size=fread(info,1,10000,file);
while(size!=(int)p-(int)info)
{
if(!strcmp(p,name)&&!strcmp(p+strlen(p)+1,password))
{
fclose(file);
return 1;
}
p+=strlen(p)+1;
p+=strlen(p)+1;
}
}
fclose(file);
return 0;
}

//添加注册信息入文件
void save(char *name,char *password)
{
FILE *file=fopen("user","a");
fwrite(name,1,strlen(name)+1,file);
fwrite(password,1,strlen(password)+1,file);
fclose(file);
}

#define PASSWORD "12345" //这里指定你要允许通过的密码,比如12345,将引号里的数字改为你想要的即可
int main()
{
char password[100];
char name[100],c[100],password1[100];
tag1: printf("press 1 to register, or 2 to login\n");//输入1为注册,输入2为登陆
while(1)
{
gets(c);
if('1'==c[0])
{
printf("please enter your name\n");//输入姓名
gets(name);
tag2: printf("please enter your password\n");//输入密码
gets(password);
printf("please enter your password again\n");
gets(password1);
if(strcmp(password,password1))
{
//两次密码不一致,重输
printf("the password you entered is different from the first one,please try again!\n");
goto tag2;
}
printf("register is completed!\n");//注册成功
//下面实现将注册信息加入文件保存
save(name,password);
goto tag1;
}
else if('2'==c[0])
{
tag3: printf("please enter your name:\n");
gets(name);
printf("please enter your password:\n");
gets(password);
if(login(name,password))//如果验证通过,则
{
printf("login successfully!\n");

//这里添加成功登陆后要执行的代码
}
else
{
printf("your name or password doesn't exist!\n");//否则重输
goto tag3;
}

}
else
{
printf("invalid input!press 1 to register, or 2 to login\n");//输入非法,重输
goto tag1;
}

}

return 0;
}

饿,写了我两个小时啊,大哥,分一定要给我啊~~~~~~

⑥ c语言怎样将输入的字符应用到函数中

getpass()函数可以使输入的字符不现实在屏幕上。#include
<conio.h>int
main(void){char
*password;password
=
getpass("Input
a
password:");cprintf("The
password
is:
%s\r\n",password);return
0;}

⑦ C语言中,用什么函数可以使输入的字符不显示在屏幕上

在输入语句之后加system("cls");这个语句可以清除屏幕之前的内容,也就是你输入完成之后屏幕上的输入数据就被清除了。。使用时要包含头文件stdlib.h
希望可以帮到你

⑧ 编一个注册登陆的程序 C语言的

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

bool search(char id[], char pass[]) {
FILE *fp;
char tid[10], tpass[10];
fp = fopen("c:\\data", "r");
while (!feof(fp)) {
fscanf(fp, "%s%s", tid, tpass);
if (strcmp(tid, id)==0 && strcmp(tpass, pass)==0) {
fclose(fp);
return true;
}
}
fclose(fp);
return false;
}

bool login() {
char id[10], pass[10];
printf("Login\nPress the id: ");
scanf("%s", id);
printf("Press the password: ");
// 可以自行将password处理成*号, 如果不会可以发信给我
scanf("%s", pass);
printf("-----------------------");
if (search(id, pass))
return true;
else
return false;
}

void _add(char id[], char pass[]) {
FILE *fp;
fp=fopen("c:\\data", "a");
// 在写入文件时可以按一定的排序方式插入,可减少以后Login时的search时间
fprintf(fp, "%s %s\n", id, pass);
fclose(fp);
}

void regis() {
char id[10], pass[10], tpass[10];
printf("Register\nPress the id: ");
scanf("%s", id);
while (true) {
printf("Press the password: ");
scanf("%s", pass);
printf("Press the password again: ");
scanf("%s", tpass);
if (strcmp(pass, tpass) != 0)
printf("The passwords you pressed are not the same!\n");
else
break;
}
_add(id, pass);
printf("-----------------------Register successfully!\n");
}

void init() {
FILE *fp;
if ((fp=fopen("c:\\data", "r")) == NULL) { // 注意,一定要有个名叫data(没有扩展名)的合法文件在C盘根目录
printf("---------File is not exist\n");
system("pause");
exit(0);
}
else
fclose(fp);
}

int main(void){
int command;
init(); // 检查data文件在不在
while (true) {
printf("-----------------------(Login: 1 Register: 2 Exit: 3)\n");
scanf("%d", &command);
printf("-----------------------\n");
// 这里可以编写command的检测语句
if (command == 3)
break;
else if (command == 1) {
if (!login())
printf("ID is not exist or password is wrong!\n");
else
printf("Login successfully!\n");
}
else
regis();
}
return 0;
}
搞定了。。。我是用成功了的。。。如果有问题就发信给我。。。。

⑨ 怎么用C+++编写口令,实现数据访问控制。

本程序涉及到C语言函数getpass(char *),该函数从键盘读取8位字符
并返回,且不在屏幕上显示。我们正好利用这一函数功能进行输入口令。 程序清单如下: #include
#include
void main()
{
char *password;
char kl[9]=\"88888888\";
inti=0;
FILE *fpl;
window(1,1,80,25); /* 屏幕背景清屏成蓝色 */
textbackground(1);
clrscr();
window(17,10,58,13);/* 开阴影窗口 */
textbackground(0);
clrscr();
for(i=0;i<=2;i++)
{
window(16,9,56,12);
textattr(14︳2<<4);
clrscr();
gotoxy(13,2);
password=(char *)getpass(\"请输入系统口令:\");
textcolor(4);
/* 若口令文件KLK.CFG存在,则从中取出口令字 */
if((fp=fopen(\"KLK.CFG\",\"rb+\"))!=NULL)
{
fseek(fp,O,SEEK_SET);
fgets(kl,9,fp);
fclose(fp);
}
if(i==2&&strcmp(password,kl)!=0)
/* 三次口令无效退出 */
{
gotoxy(13,2);
cputs(\"口令错误,退出!!\");
getch();
exit(0);
}
if(stcmp(password,kl)!=0)
{
gotoxy(13,2);
cputs(\"口令错误,重输!!\");
getch();
}
else break;
}
/* 进入主程序体 */
textbackground(1);
window(1,1,80,25);
clrscr();
gotoxy(10,10);
cputs(\"执行用户主体程序……按任意键进行更改口令!\");
getch();
changkl();/*用户程序中调用修改口令函数*/
} changkl() /* 修改口令子函数 */
{
char *klk;
char buf[1];
FILE *fp;
window(17,16,58,19);/* 开阴影窗口 */
textbackground(0);
clrscr();
window(16,15,56,18);
textattr(14︳4<<4);
clrscr();
gotoxy(8,4);
cputs(\"请修改口令字,必须为八位字符\");
gotoxy(14,2);
klk=(char *)getpass(\"请输入新口令:\");
gotoxy(14,2);
textcolor(2);
if(srlen(klk)!=8)
{
cputs(\"口令字无效,返回!!\");
getxh();
return;
}
cputs(\"口令修改成功!!\");
if((fp=fopen(\"KLK,CFG\".\"w\"))!=null)
/* 保存口令到文件KLK.CFG */
{
fputs(klk,fp);
buf[0]=0xia;
fwrite(&buf[0],1,1,fp);
fclose(fp);
}
getch();
returm;
}

⑩ 如何使C语言中getpass()函数接受的数据超过8位

getpass() 不是ANSI C 标准库函数。不是所有编译器都有getpass()函数,就算有,它的定义也可能不同。GNU C 库 没有规定 数据长度,所以长度没有限制。 对于可设 PASS_MAX 参数的 getpass() ,你可以 设它的长度PASS_MAX 。不能设的 可以自己写 getpass()函数:

#include<stdio.h>
#include<stdlib.h>
#include <conio.h>

void main()
{
unsigned char x[100];
int i;
i=0;
while (1)
{
x[i] = getch();
if (x[i] == '\n' || x[i] == '\r') break;
putch('*');
i++;
}
printf("\n%s",x);
exit(0);
}