飞道的博客

c++控制台密码管理系统

320人阅读  评论(0)

对您有一点点用,或者喜欢,点点赞,点点关注可以吗,谢谢!

功能介绍:1.怎么创建密码,输入两次

                  2.怎么修改密码

                  3.怎么删除密码

目录

​1.主界面

2. 功能代码


1.

 

2.

 

 

是不是有点意思,那还不ctrl-c ctrl-v   弄入你的IDE环境下,试下


  
  1. // mima.cpp: 主项目文件。
  2. #include "stdafx.h"
  3. ///
  4. #include <iostream>
  5. #include <conio.h>
  6. #include <string.h>
  7. #include <fstream>
  8. //#include <windows.h>
  9. using namespace std;
  10. void display(); //主界面函数
  11. void xuanze(); //选择函数
  12. int read_file(); //读取密码文件
  13. void write_file(); //写入密码文件
  14. void Create_mima(); //创建密码
  15. void YanZheng_mima(); //验证密码
  16. void Chang_mima(); //修改密码
  17. void delete_mima(); //删除密码
  18. //
  19. void jiami_suanfa(char* str); //加密解密算法
  20. char mimaStr[ 100]; //全局变量
  21. //以上是函数的声明部分
  22. //下面是函数的实现部分
  23. void display() //主界面函数
  24. {
  25. system( "cls");
  26. read_file();
  27. cout<< "\t\t************************************************"<< endl;
  28. cout<< "\t\t\t\t欢迎使console密码系统"<< endl;
  29. cout<< "\t\t************************************************"<< endl;
  30. if( strlen(mimaStr)== 0) cout<< "\t\t\t\t [1] 创建密码"<< endl;
  31. else cout<< "\t\t\t\t 创建密码"<< endl; //密码已经存在就不能创建了
  32. cout<< "\t\t\t\t [2] 验证密码"<< endl;
  33. cout<< "\t\t\t\t [3] 修改密码"<< endl;
  34. cout<< "\t\t\t\t [4] 删除密码"<< endl;
  35. cout<< "\t\t\t\t [5] 退出系统"<< endl;
  36. cout<< "\t\t************************************************"<< endl;
  37. xuanze();
  38. }
  39. void xuanze()
  40. {
  41. cout<< "\t\t请输入你要进行的操作数: ";
  42. char ch;
  43. L: ch=getch();
  44. if ((ch== '1' && strlen(mimaStr)== 0) || ch== '2' || ch== '3' || ch== '4' || ch== '5')
  45. {
  46. switch(ch)
  47. {
  48. case '1':Create_mima();
  49. break;
  50. case '2':YanZheng_mima();
  51. break;
  52. case '3':Chang_mima();
  53. break;
  54. case '4':delete_mima();
  55. break;
  56. case '5': exit( 0);
  57. break;
  58. }
  59. }
  60. else goto L;
  61. }
  62. int read_file() //读取密码文件
  63. {
  64. L: ifstream infile("MiMa_record.txt");
  65. if (!infile)
  66. {
  67. write_file();
  68. goto L;
  69. }
  70. else
  71. infile>>mimaStr;
  72. return 1;
  73. }
  74. void write_file()//写入密码文件
  75. {
  76. ofstream outfile("MiMa_record.txt");
  77. if (!outfile)
  78. {
  79. cout<< "can not open the file!"<< endl;
  80. return;
  81. }
  82. else
  83. outfile<<mimaStr;
  84. }
  85. void jiami_suanfa(char* str) //加密解密算法
  86. {
  87. int len= strlen(str);
  88. for ( int i= 0;i<len;i++)
  89. str[i]=str[i]^ 'g';
  90. }
  91. void Create_mima() //创建密码
  92. {
  93. system( "cls");
  94. char ch;
  95. int i= 0;
  96. char str[ 100]; //确认密码存放处
  97. cout<< "请输入新建密码,按Enter结束(大于等于6位数): ";
  98. ch=getch();
  99. while (i< 100)
  100. {
  101. if (ch== 13 && i> 5) break;
  102. else if(ch== 13)ch=getch();
  103. else
  104. {
  105. cout<< "*";
  106. mimaStr[i++]=ch;
  107. ch=getch();
  108. }
  109. }
  110. mimaStr[i]= '\0'; //结束标志
  111. i= 0;
  112. cout<< endl<< "请输入确认密码,按Enter结束(大于等于6位数): "; //第二次输入密码
  113. ch=getch();
  114. while (i< 100)
  115. {
  116. if (ch== '\r' && i> 5) break;
  117. else if(ch== '\r')ch=getch();
  118. else
  119. {
  120. cout<< "*";
  121. str[i++]=ch;
  122. ch=getch();
  123. }
  124. }
  125. str[i]= '\0'; //结束标志
  126. if ( strcmp(mimaStr,str)== 0)
  127. {
  128. jiami_suanfa(mimaStr);
  129. write_file();
  130. cout<< endl<< "创建密码成功!,任意键返回..."<< endl;
  131. ch=getch();
  132. display();
  133. }
  134. else
  135. {
  136. cout<< "两次输入密码不一样,创建失败! 继续创建密码按Enter,任意键返回..."<< endl;
  137. ch=getch();
  138. if (ch== '\r')Create_mima();
  139. else display();
  140. }
  141. }
  142. void YanZheng_mima() //验证密码
  143. {
  144. read_file();
  145. system( "cls");
  146. char ch;
  147. char str[ 100];
  148. int i= 0;
  149. cout<< "请输入你要验证的密码,Enter结束: ";
  150. ch=getch();
  151. while (i< 100)
  152. {
  153. if (ch== '\r' && i> 5) break;
  154. else if(ch== '\r')ch=getch();
  155. else
  156. {
  157. cout<< "*";
  158. str[i++]=ch;
  159. ch=getch();
  160. }
  161. }
  162. str[i]= 0;
  163. cout<< endl;
  164. jiami_suanfa(mimaStr); //解密
  165. if ( strcmp(str,mimaStr)== 0)
  166. {
  167. cout<< "恭喜!验证成功!任意键返回..."<< endl;
  168. ch=getch();
  169. display();
  170. }
  171. else
  172. {
  173. cout<< "验证不成功!按Enter继续验证,任意键返回..."<< endl;
  174. ch=getch();
  175. if (ch== '\r')YanZheng_mima();
  176. else display();
  177. }
  178. }
  179. void Chang_mima() //修改密码
  180. {
  181. read_file();
  182. system( "cls");
  183. char ch;
  184. char str[ 100];
  185. int i= 0;
  186. cout<< "请输入原来的密码,Enter结束: ";
  187. ch=getch();
  188. while (i< 100)
  189. {
  190. if (ch== '\r' && i> 5) break;
  191. else if(ch== '\r')ch=getch();
  192. else
  193. {
  194. cout<< "*";
  195. str[i++]=ch;
  196. ch=getch();
  197. }
  198. }
  199. str[i]= '\0';
  200. cout<< endl;
  201. i= 0;
  202. jiami_suanfa(mimaStr); //解密
  203. if ( strcmp(str,mimaStr)== 0)
  204. {
  205. cout<< endl<< "请输入修改密码,按Enter结束(大于等于6位数): ";
  206. ch=getch();
  207. while (i< 100)
  208. {
  209. if (ch== '\r' && i> 5) break;
  210. else if(ch== '\r')ch=getch();
  211. else
  212. {
  213. cout<< "*";
  214. mimaStr[i++]=ch;
  215. ch=getch();
  216. }
  217. }
  218. mimaStr[i]= '\0'; //结束标志
  219. i= 0;
  220. cout<< endl<< "请输入确认密码,按Enter结束(大于等于6位数): "; //第二次输入密码
  221. ch=getch();
  222. while (i< 100)
  223. {
  224. if (ch== '\r' && i> 5) break;
  225. else if(ch== '\r')ch=getch();
  226. else
  227. {
  228. cout<< "*";
  229. str[i++]=ch;
  230. ch=getch();
  231. }
  232. }
  233. str[i]= '\0'; //结束标志
  234. if ( strcmp(mimaStr,str)== 0)
  235. {
  236. jiami_suanfa(mimaStr);
  237. write_file();
  238. cout<< endl<< "修改密码成功!,任意键返回..."<< endl;
  239. ch=getch();
  240. display();
  241. }
  242. else
  243. {
  244. cout<< endl<< "两次输入密码不一样,修改失败! 继续修改密码按Enter,任意键返回..."<< endl;
  245. ch=getch();
  246. if (ch== '\r')Chang_mima();
  247. else display();
  248. }
  249. }
  250. else
  251. {
  252. cout<< endl<< "输入密码不匹配!你不能修改该密码!任意键返回..."<< endl;
  253. ch=getch();
  254. display();
  255. }
  256. }
  257. void delete_mima() //删除密码
  258. {
  259. read_file();
  260. system( "cls");
  261. char ch;
  262. char str[ 100];
  263. int i= 0;
  264. cout<< "请输入原来的密码,Enter结束: ";
  265. ch=getch();
  266. while (i< 100)
  267. {
  268. if (ch== '\r' && i> 5) break;
  269. else if(ch== '\r')ch=getch();
  270. else
  271. {
  272. cout<< "*";
  273. str[i++]=ch;
  274. ch=getch();
  275. }
  276. }
  277. str[i]= '\0';
  278. cout<< endl;
  279. i= 0;
  280. jiami_suanfa(mimaStr); //解密
  281. if ( strcmp(str,mimaStr)== 0)
  282. {
  283. cout<< "确定删除请按'y'or'Y',任意键取消返回..."<< endl;
  284. ch=getch();
  285. if (ch== 'y' || ch== 'Y')
  286. {
  287. mimaStr[ 0]= '\0';
  288. write_file();
  289. cout<< "删除成功,任意键返回..."<< endl;
  290. ch=getch();
  291. display();
  292. }
  293. else display();
  294. }
  295. else
  296. {
  297. cout<< endl<< "输入密码不匹配!你不能删除该密码!任意键返回..."<< endl;
  298. ch=getch();
  299. display();
  300. }
  301. }
  302. //mian函数
  303. void main()
  304. {
  305. display();
  306. }

        是不是和给出的效果一致呢, 以上的密码只是简单的异或操作加密,你可以在这基础上加入你的专业级的加密算法试试哈, 什么 des aes都可以哈!

记得点赞和关注哟!

 

 


转载:https://blog.csdn.net/kaizi318/article/details/109560184
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场