C语言实现密码输入显示星号 VS2010 亲测通过

// 登录界面   第一次可设置密码   之后的登录要输入密码进行验证    密码长度8~12
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>
#define LEN 12




static int count=0;
int main(){
char password[LEN+1];
memset(password,NULL,LEN+1);
char ch;
if(count==0){
loop_passwordSet:printf("this is your first time to login,pls set your password.\n");
printf("the length of password has a length between 8~12 without any nonprint charators.\n");
int inputLength=0;
ch=getch();
while(isprint(ch)){
if(ch!=' '){
putchar('*');
password[inputLength]=ch;
inputLength++;
ch=getch();
}
if(!isprint(ch))
break;
if(inputLength==LEN)
break;
}
printf("\n");
printf("what you have just input is: %s\n",password);
printf("Press Y/N to confirm.\n");
ch=getch();
switch(ch){
case 'Y'  :{
printf("password set completed!\n");
count=1;
break;
}
 case 'y'  :{
printf("password set completed!\n");
count=1;
break;
}
case 'N': {
printf("password set canceled.\n");
goto loop_passwordSet;
}
case 'n': {
printf("password set canceled.\n");
goto loop_passwordSet;
}

default: {
printf("invalid input,pls try again.\n");
goto loop_passwordSet;
}
}
}
if(count==1){
char toMatchPassword[LEN+1];
memset(toMatchPassword,NULL,LEN+1);
int toMatchLength=0;
loop_inputPassword: printf("input your password to login.\n");
ch=getch();
while(isprint(ch)){
if(ch!=' '){
putchar('*');
toMatchPassword[toMatchLength]=ch;
ch=getch();
toMatchLength++;
}
if(!isprint(ch)){
break;
}
if(toMatchLength==LEN){
break;
}
}
if(strcmp(password,toMatchPassword)==0){
printf("password Correct!  LOGIN SUCCESS!\n");
printf("**********************\n");
printf("**********************\n");
printf("**   WELCOME       **\n");
printf("**********************\n");
printf("**********************\n");
printf("***********   By ZHAOs*\n");
Sleep(2000);
}
if(strcmp(password,toMatchPassword)!=0){
printf("Password input error!  Press Y to try again!\n");
char ch=getch();
switch(ch){
case 'Y':{
goto loop_inputPassword;
}
case 'y':{
goto loop_inputPassword;
}
case 'N':{
exit(0);
}
case 'n':{
exit(0);
}
default:
{
printf("invalid input, now the system would abort....\n");
Sleep(2000);
exit(0);
}
}
}
}


system("pause");
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值