① c語言密碼輸入
簡單的
用一個字元數組來存密碼
再用一個字元數組接收你的輸入,然後用strcmp
來比較,如果返回0則密碼是正確的
#include"stdio.h"
#include"string.h"
intmain()
{
charmima[100]="YuanShi888";
charinput[100]={0};
printf("請輸入密碼:");
gets(input);
if(strcmp(mima,input)==0)
printf("恭喜你,密碼正確! ");
else
printf("對不起,密碼輸入錯誤! ");
}
② 求一個純c語言寫的口令驗證,若密碼正確則進入主函數,若密碼不正確則推出程序。
#include "stdio.h"
#include "string.h"
void MainProc()
{
}
void main()
{
char pwd[]="123456";
char Ipt[20];
printf("Input password:");
scanf("%s",Ipt);
if(strcmp(pwd,Ipt)!=0)printf("
Password error,Access denied!");
else MainProc();
}
這樣可以不,不滿意請追問。
③ 進入前輸入密碼的C語言怎麼寫
//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#define PS "abc" /*默認密碼*/
#define MPS 3 /*失敗重試次數*/
char *getpas(char *s,int n) /*輸入密碼*/
{
char c;
int i;
memset(s,0,n);
for (i = 0; i<n-1; i++) {
c=getch();
if (isprint(c)) {
s[i]=c=='\r'?'\0':c;
putchar('*');
}
if (c=='\r') break;
}
putchar('\n');
return s;
}
int login(void) /*密碼驗證函數,如果通過驗證則返回1,否則返回0*/
{
char ap[80];
int fg=0;
do
{
puts("密碼:");
if (strcmp(getpas(ap,80),PS)&&fg<=MPS) {
printf("輸入有誤,還有%d次機會\n",MPS-fg);
fg++;
}
else if (strcmp(ap,PS)) puts("密碼錯誤,程序結束!");
else {
puts("密碼正確!");
return 1;
}
}while (fg<=MPS);
return 0;
}
int main(void)
{
if (login()) { /*如果密碼驗證成功,則開始執行程序的主體部分*/
printf("歡迎使用\n");
}
else printf("無此許可權\n"); /*如果驗證失敗,則顯示提示信息並退出程序*/
return 0;
}
//---------------------------------------------------------------------------
④ C語言題目 輸入密碼看是否匹配
姓名部分較簡單,你可以自己寫。
口令部分寫好了。
密碼輸入:允許回退鍵更正輸入,回車結束輸入
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main()
{
char p[50];
char UserName[50]="student";
char password[50]="iamtiger";
int i=0;
int n;
printf("Please enter your name:\n");
scanf("%s",UserName);
n=0;
Loop:
i=0;
printf("Please enter your passwd:\n");
fflush(stdin);
while ( i < 50 ){
p[i] = getch();
if (p[i] == '\r') break;
if (p[i] == '\b') { i=i-1; printf("\b \b"); } else {i=i+1;printf("*");};
}
p[i]='\0';
if ( strcmp(password,p)==0) printf("\npasswd is right!\n");
else {
printf("\npassword wrong\n");
n++;
if (n>=3) { printf("Err bye !\n"); return 0;} else goto Loop;
};
return 0;
}
⑤ 用C語言:根據給定的演算法,判斷輸入的密碼是否正確
#include<stdio.h>
void main()
{
int n,password=123456,i=1;
while(1)
{
printf("輸入密碼:");
scanf("%d",&n);
if(n==password)
printf("Welcome to use the software\n");
else
{
if(i<3)
printf("剩餘的可輸入密碼的次數為:%d\n",3-i);
else
printf("Password error ! You can not use the software\n");
i++;
}
if(i>=4||n==password)break;
}
}
這個是不需要用return的,簡明一點,初學的應該會
⑥ 在c語言中如何實現1、 編程實現用戶登錄問題,如果用戶名和密碼都輸入正確,則提示「歡迎登陸!」,假定用
#include<stdio.h>
void main()
{
char name;
int code;
bool b=true;
while(b)
{
printf("\n請輸入用戶名:");
scanf("%s",&name);
printf("\n請輸入密碼:");
scanf("%d",&code);
if(name=='h'&&code==0)
{
printf("歡迎光臨\n");
b=false;
}
else{
printf("重新登錄\n");
}
}
}
希望對你有所幫助,不明白hi我。。
⑦ 用C語言實現讓用戶輸入密碼,判斷正確否,若正確開始進入下一步新的程序的演算法
#include
void
main()
{
int
n,password=123456,i=1;
while(1)
{
printf("輸入密碼:");
scanf("%d",&n);
if(n==password)
printf("welcome
to
use
the
software\n");
else
{
if(i<3)
printf("剩餘的可輸入密碼的次數為:%d\n",3-i);
else
printf("password
error
!
you
can
not
use
the
software\n");
i++;
}
if(i>=4||n==password)break;
}
}
這個是不需要用return的,簡明一點,初學的應該會
⑧ C語言寫個程序,已知密碼password=123 要求用戶輸入密碼passWord,判斷是否正確,輸入錯誤超過3次則退出
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main(void)
{
char password[32];
int i=3;
do{
printf("請輸入密碼:(還有%d次機會)",i);
scanf("%s",&password);
if(0==strcmp(password,"123"))
{
printf("密碼輸入正確! ");
break;
}
else
{
printf("密碼輸入錯誤,請重新輸入! ");
i--;
}
}while(i>0);
getch();
return 0;
}
⑨ 如何設置c語言程序1)管理員先設置用戶名和密碼,密碼以*輸出。輸入驗證,若密碼正確,提示進入系統,
#include <stdio.h>
int main()
{
int i=0;
char c;
while(i<20&&(c!='\n'))
{ c=getch();
putchar('*');
++i;
}
getch();
}
⑩ 輸入密碼正確(三次以內),進入下一指令(c語言程序作答)
#include<stdio.h>
voidabc()
{
printf("correct ");
}
voidmain()
{
intflag=0,i=0,j=0,count=0;
charp[20],c;
charpassword[20]="123456";
for(j=0;j<3;j++)
{
c=0;
count=0;
i=0;
printf("請輸入密碼 ");
while((c=getchar())!=' ')
{
p[i]=c;
i++;
}
p[i]='