同学让我帮改下登陆,就是把明文密码“12345”改成密文“******” void pass() { char UserName[30]; char Password[20]; int i=0; cout<<"*************************************\n"; cout<<"\n\t管理员名和登录密码都只有4次机会,如果超过将自动退出系统!\n\n"; cout<<"*************************************\n"; cout<<"\n请输入管理员名:"; cin>>UserName; while(strcmp(UserName,"admin")!=0) { if(i>=3) exit(0); //超过4次则登录失败,退出系统 i++; cout<<"\n管理员名无效,请重新输入:"; cin>>UserName; } cout<<"\n请输入密码:"; cin>>Password; while(strcmp(Password,"12345")!=0) { if(i>=3) exit(0); //超过4次则登录失败,退出系统 i++; cout<<"\n密码输入错误,请重新输入:"<<endl; cin>>Password; } cout<<"\n\t\t欢迎管理员的到来!!!"; }
应该是类似这样吧,不过unix是没有自带的conio.h的,我也就不去试了。 [mw_shl_code=c,true]#include <stdio.h> #include <conio.h> int main() { char ch; printf("plz input the pwd:"); while(ch = getch()) { if (ch == '\n') { printf("\n"); break; } //append ch after password array printf("*"); } return 0; }[/mw_shl_code]