當前位置:首頁 » 編程語言 » 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);
}