Home
Problem
Status
Contest
Workbook
User
Group
Forum
Register
Login
{"managingGroups":{},"author":"Acceptor","updateTime":1544536819000,"title":"TMP_SYSTEM","dislikeCnt":0,"content":"`A_New_One.cpp`, **I\u0027m so weak**\n![超人熊](http://img.uoj.ac/utility/bear-flying.gif)\n```cpp\n#include \u003cbits/stdc++.h\u003e\n#include \u003cwindows.h\u003e\n#include \u003cconio.h\u003e\n#define maxn 1010\nusing namespace std;\n// Add function of English or Chinese\n// password leagle.\n// login status.\n// password reset.\n\nint FL;\n\nstruct users{\n string name,passwd;\n void clear(){\n name.clear();\n passwd.clear();\n }\n void read(bool type){\n if(type){\n printf(\"%s\\n\",FL?\"please input your username:\":\"请输入您的用户名\");\n cin \u003e\u003e name;\n }\n else{\n printf(\"%s\\n\",FL?\"please input your password:\":\"请输入您的密码\");\n while(1){\n char ch\u003dgetch();\n if(ch\u003d\u003d13) break;\n if(ch\u003d\u003d\u0027\\b\u0027){\n if(passwd.empty()) continue;\n passwd.erase(--passwd.end());\n printf(\"\\b \\b\");\n }\n else{\n passwd+\u003dch;\n putchar(\u0027*\u0027);\n }\n }\n putchar(\u0027\\n\u0027);\n }\n }\n void insert(){clear();read(1),read(0);}\n bool operator\u003d\u003d(const users \u0026A)const{\n return name\u003d\u003dA.name;\n }\n bool operator\u003c(const users \u0026A)const{\n return name \u003c A.name;\n }\n}a[maxn];\nofstream pwdout(\"data.txt\",ios::app);\nifstream datain(\"data.txt\");\nset \u003cusers\u003e s;\n\nint n,num;\nchar opt[10];\nusers tmp;\nbool ischanged;\n\nbool equ(const users \u0026A,const users \u0026B){\n return A.name\u003d\u003dB.name \u0026\u0026 A.passwd\u003d\u003dB.passwd;\n}\n\nnamespace info{\n\tvoid About(){\n\t\tprintf(\"\\t\\tWelcome to using this system(version: test)\\n\");\n\t puts(\"\\t\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\");\n\t FL \u003d MessageBox(0, \"please choose your use language: click No for English, Yes for Chinese\", \"choose\", 1);\n\t FL--;\n\t\twhile(datain \u003e\u003e tmp.name \u003e\u003e tmp.passwd) a[++num]\u003dtmp,s.insert(a[num]);\n\t\n\t printf(\"%s\\n\",FL?\"please input \u0027r\u0027 if you wanna register a new id, or input \u0027l\u0027 for login\":\"如果您想注册用户请输入\u0027r\u0027, 否则输入\u0027l\u0027进行登录。\");\n\t printf(\"%s\\n\",FL?\"if you wanna change your password, input \u0027c\u0027.\":\"如果您想更改密码,请输入\u0027c\u0027.\");\n\t printf(\"\\n%s\\n\",FL?\"if you had forget your password, input \u0027f\u0027, and we will send a mail to your E:\":\"若果您忘记了自己的密码,请输入\u0027f\u0027,我们将会给您的E盘发邮件。\");\n\t printf(\"\\n%s\\n\\n\",FL?\"anytime input \u0027q\u0027 for quit\":\"随时输入\u0027q\u0027退出本系统.\");\n\t}\n}\n\n\nvoid Read_pwd(string\u0026 now){\n while(1){\n char ch\u003dgetch();\n if(ch\u003d\u003d13) break;\n if(ch\u003d\u003d\u0027\\b\u0027){\n if(now.empty()) continue;\n now.erase(--now.end());\n printf(\"\\b \\b\");\n }\n else{\n now+\u003dch;\n putchar(\u0027*\u0027);\n }\n }\n putchar(\u0027\\n\u0027);\n}\n\n\nint Work(){\n cin \u003e\u003e opt;\n if(opt[0]\u003d\u003d\u0027q\u0027) return 0;\n if(opt[0]\u003d\u003d\u0027f\u0027){\nofstream mailout(\"E:\\\\reset_password.log\");\n \ttmp.clear();\n \ttmp.read(1);\n \tbool OK\u003d0;\n \tfor(int i\u003d1;i\u003c\u003dnum;i++){\n \t\tif(tmp\u003d\u003da[i]){\n \t\t\tmailout \u003c\u003c \"your password is \\\"\" \u003c\u003c a[i].passwd \u003c\u003c \"\\\" , please reset it as soon as possible.\\n\";\n\t\t\t\tprintf(\"%s\\n\",FL?\"reset mail has been send successfully, please check it.\\n\":\"邮件已经成功发送,请尽快核查。\");\n\t\t\t\tOK\u003dtrue;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!OK) printf(\"%s\\n\",FL?\"no such user\":\"抱歉,没有此用户。\");\nmailout.close();\n\t}\n else if(opt[0]\u003d\u003d\u0027r\u0027){\n while(1){\n tmp.insert();\n if(s.count(tmp)) printf(\"%s\\n\",FL?\"sorry, username has exited, please use another id\":\"抱歉,用户名已存在,请使用其他id。\");\n else break;\n }\n s.insert(tmp);\n a[++num]\u003dtmp;\n pwdout \u003c\u003c endl \u003c\u003c tmp.name \u003c\u003c \u0027 \u0027 \u003c\u003c tmp.passwd \u003c\u003c endl;\n printf(\"%s\\n\",FL?\"register succeed.\":\"注册成功\");\n }\n else if(opt[0]\u003d\u003d\u0027l\u0027){\n tmp.insert();\n bool flag\u003d0;\n// for(int i\u003d1;i\u003c\u003dnum;i++){\n// cout \u003c\u003c tmp.name \u003c\u003c \u0027 \u0027 \u003c\u003c tmp.passwd \u003c\u003c endl;\n// }\n for(int i\u003d1;i\u003c\u003dnum;i++){\n if(equ(tmp,a[i])){\n flag\u003dtrue;\n break;\n }\n }\n if(flag){\n if(FL) cout \u003c\u003c \"user \" \u003c\u003c tmp.name \u003c\u003c \" has logged in\" \u003c\u003c endl;\n else cout \u003c\u003c \"用户 \" \u003c\u003c tmp.name \u003c\u003c \" 登录成功\" \u003c\u003c endl;\n }\n else{\n if(FL) cout \u003c\u003c \"username or password wrong, please try it again. input \u0027l\u0027 first.\" \u003c\u003c endl;\n else cout \u003c\u003c \"用户名或者密码错误,请重试,别忘记输入\u0027l\u0027。\" \u003c\u003c endl;\n }\n }\n else if(opt[0]\u003d\u003d\u0027c\u0027){\n ::ischanged\u003d1;\n tmp.insert();bool suc\u003d0;\n// printf(\"%s\\n\",FL?\"please input your new password again.\":\"请再次输入新密码。\");\n// string tmpaswd;\n// Read_pwd(tmpaswd);\n// while(tmpaswd !\u003d tmp.passwd){\n// printf(\"%s\\n\",FL?\"two password not math.\":\"抱歉,您两次输入的密码不一致。请重试。\");\n// tmp.insert();\n// printf(\"%s\\n\",FL?\"please input your new password again.\":\"请再次输入新密码。\");\n// \n// }\n for(int i\u003d1;i\u003c\u003dnum;i++){\n if(equ(tmp,a[i])) {suc\u003d1;break;}\n }\n if(!suc) printf(\"%s\\n\",FL?\"no such user\":\"抱歉,没有此用户。\");\n else {\n printf(\"%s\\n\",FL?\"please input your new password:\":\"请输入您的新密码\");\n string pwd1,pwd2;\n Read_pwd(pwd1);\n printf(\"%s\\n\",FL?\"plwase input your new password again:\":\"请再次输入新密码\");\n Read_pwd(pwd2);\n while(pwd1 !\u003d pwd2){\n printf(\"%s\\n\",FL?\"two password not math.\":\"抱歉,您两次输入的密码不一致。请重试。\");\n printf(\"%s\\n\",FL?\"please input your new password:\":\"请输入您的新密码\");\n Read_pwd(pwd1);\n printf(\"%s\\n\",FL?\"plwase input your new password again:\":\"请再次输入新密码\");\n Read_pwd(pwd2);\n }\n printf(\"%s\\n\",FL?\"password changed successfully.\":\"密码更改成功。\");\n for(int i\u003d1;i\u003c\u003dnum;i++){\n if(equ(tmp,a[i])){a[i].passwd\u003dpwd2;break;}\n }\n }\n }\n return 1;\n}\n\nint main(){\n\tinfo::About();\n\twhile(Work());\n pwdout.close();\n datain.close();\n if(ischanged){\n // cout \u003c\u003c \"num \u003d \" \u003c\u003c num \u003c\u003cendl;\nofstream tmpout(\"tmp.txt\");\n for(int i\u003d1;i\u003c\u003dnum;i++)\n tmpout \u003c\u003c a[i].name \u003c\u003c \u0027 \u0027 \u003c\u003c a[i].passwd \u003c\u003c endl;\n tmpout.close();\n system(\"del data.txt\");\n system(\"ren tmp.txt data.txt\");\n }\n system(\"pause\");\n return 0;\n}\n// unicorn.nyf\n```","likeCnt":0,"createTime":1544536819000,"isWorkbook":false,"viewCnt":909,"openness":1,"fav":false,"id":779,"trustable":false}