项目优化4-隐藏密码输入-别看了,看懂的都不是一般人

在这里插入图片描述

#include <iostream>
#include <windows.h>
#include <string>
#include "hacker.h"

using namespace std;

#define  WIDTH   60//宽度
#define  HIEGHT  30//高度

//设置终端 界面大小
void  terminal(void) {  //终端界面
	char print[68];  //打印
	sprintf(print, "mode con cols=%d lines=%d", WIDTH, HIEGHT); //每个字母中间不能有空格
	system(print);
}

//初始化
void Initialize_the(void) {  
	string name;  //名字
	string password; //密码

	while (1) {
		system("cls");
		cout << "请输入账号:";
		cin >> name;
		cout << "请输入密码:";
		cin >> password;

		//判断密码是否正确
		if( name =="dandan" && password =="123456") {
			break;
		} else {
			cout << "账号或密码错误!!!" << endl;
			cout << "请重新输入。。。" << endl;
			system("pause");
		}
	}
}
//居中打印菜单主题
void print_theme(string print) {
	int blank= (WIDTH - print.length()) / 2;
	for(int i=0; i<blank; ++i) {
		printf(" ");
    }
	cout << print << endl;
}


//菜单选项   居中打印 
void The_menu(void) {
	string print[] ={
		"1。404攻击",
		"2.篡改攻击",
		"3.攻击恢复",
		"4.攻击查看",
		"5.退出",
		"请选择:",
	};

    system("cls");
    print_theme("---黑客攻击系统---");
	//计算菜单  每个单元有多大   并打印空格
	int print_unit = sizeof(print) / sizeof(print[0]);
	int print_and =0;  //和
	for(int i=0; i<print_unit; ++i) {
		if(print[i].length() > print_and) {
			print_and = print[i].length();
		}
	}
	
	int print_empty = (WIDTH - print_and) / 2;
	for(int i=0; i<print_unit; ++i) {
		for(int i=0; i<print_empty; ++i) {HHHH
				printf(" ");
	    }
		cout << print[i] << endl;
	}

	/**
	system("cls");
	//登录菜单
	cout << "---黑客攻击系统---" << endl;
	cout << "1.404攻击" << endl;
	cout << "2.篡改攻击" << endl;
	cout << "3.攻击修复" << endl;
	cout << "4.查看攻击记录" << endl;
	cout << "5.退出" << endl;
	cout << "请选择:";
	**/

}

int Menu_options(void) {
	int n = 0;
	while (1) {
		cin >> n;
		if (cin.fail()) {
			cin.clear();
			cin.clear();
			cout << "无效输入. 请重新输入." << endl;
			system("pause");
		} else {
			break;
		}
	}
	return n;
}

void The_menu1(void) {
	//int hk_404(char *id, char *response) ;
	char id[36];  //网站的id
	char result[MAXSIZE]; //攻击服务器的返回结果

	system("cls");
	//居中打印
	print_theme("404攻击"); 

	cout << "请输入网站id: ";
	scanf_s("%s", id, sizeof(id));

	//攻击时打印提示信息
    cout << "正在404攻击!!!" << endl;

	//发起攻击  
	hk_404(id, result);
	 
	//攻击完打印返回结果 为GBK编码
	//把攻击result编码 转换成jbk编码  保存到retstr里面  并打印输出
    string retstr=	UTF8ToGBK(result);
	cout << retstr << endl;
	system("pause");
	/**
	system("cls");
	cout << "404攻击" << endl;
	cout << "待实现。。。" << endl;
	system("pause");
	**/
}

void The_menu2(void) {
	system("cls");
	//cout << "篡改攻击" << endl;
	//cout << "待实现。。。" << endl;
	//system("pause");
	char id[36];  //网站的id
	char result[MAXSIZE]; //攻击服务器的返回结果
	string str;
	string  para;  //打印篡改信息
	//居中打印
	print_theme("篡改攻击"); 


	cout << "请输入篡改网站id:";
	scanf_s("%s", id, sizeof(id));

	//攻击是打印提示信息
	cout << "正在攻击" << endl;
	cout << "请输入嵌入的内容:";
	cin >>  para;

	GBKToUTF8(para);  //gbk转换
	//发起攻击
	hk_tamper(id, (char*)(para.c_str()), result);

	//攻击完打印返回结果 为GBK编码
	//把攻击result编码 转换成jbk编码  保存到retstr里面  并打印输出
    string retstr=	UTF8ToGBK(result);
	cout << retstr << endl;
	system("pause");
}

void The_menu3(void) {
	char id[36];  //网站的id
	char result[MAXSIZE]; //攻击服务器的返回结果
	system("cls");
	//居中打印
	 print_theme("攻击恢复"); 
	

	cout << "请输入恢复网站id:";
	scanf_s("%s", id, sizeof(id));
	
	//恢复网站
    hk_restore(id, result);

	//攻击完打印返回结果 为GBK编码
	//把攻击result编码 转换成jbk编码  保存到retstr里面  并打印输出
    string retstr=	UTF8ToGBK(result);
	cout << retstr << endl;
	system("pause");
	/**
	system("cls");
	cout << "攻击修复" << endl;
	cout << "待实现。。。" << endl;
	system("pause");
	**/
}

void The_menu4(void) {
	char id[36];  //网站的id
	char result[MAXSIZE]; //攻击服务器的返回结果

	system("cls");
	//居中打印
	 print_theme("查看攻击记录"); 
    cout << "请输入查看网站id:";
	scanf_s("%s", id, sizeof(id));
	
	hk_record(id, result);

	
	//攻击完打印返回结果 为GBK编码
	//把攻击result编码 转换成jbk编码  保存到retstr里面  并打印输出
    string retstr=	UTF8ToGBK(result);
	cout << retstr << endl;
	system("pause");

	/**
	system("cls");
	cout << "查看攻击记录" << endl;
	cout << "待实现。。。" << endl;
	system("pause");
	**/
}


void The_menu6(void) {
	system("cls");
	cout << "输入错误请重新输入..;...." << endl;
	system("pause");
}

int main(void) {
	terminal();  //终端界面
	Initialize_the(); //初始化
	while(1) {
		The_menu(); //菜单
		int p = Menu_options(); //菜单选项
			switch (p) {
				case 1:
					The_menu1();
					break;
				case 2:
					The_menu2();
					break;	
				case 3:
					The_menu3();
					break;
				case 4:
					The_menu4();
					break;
				case 5:
					return 0;
					break; //结束
				default:
					The_menu6(); 
					break;
			}
	}
	system("pause");
	return 0;
}

在这里插入图片描述

项目优化4
隐藏密码输入
#include<conio.h>
void input_pwd(char pwd[], int max_len) {
	char c;
	int i = 0;
		
	while (1) {
		c = getch();
        // getch不从输入缓冲区中读取
		//在getch中,把回车按键输入,识别为回车符'\r'
        //在getchar中,把回车按键输入,识别为换行符'\n'
		if (c == '\r' || i >= max_len) {  
			pwd[i] = 0;
			break;
		}
		pwd[i++] = c;
		printf("*", c);
	}
	printf("\n");
}

void login(void) {
	string name;
	//string pwd;
	char pwd[16];

	while (1) {
		system("cls");

		std::cout << "请输入账号:";
		std::cin >> name;

		std::cout << "请输入密码:";
		//std::cin >> pwd;
		input_pwd(pwd, sizeof(pwd));

		if (name == "54hk" && !strcmp(pwd, "123456")) {
			//break;
			return;
		} else {
			cout << "用户名或密码错误!" << endl;
			system("pause");
		}
	}
}

在这里插入图片描述

发布了73 篇原创文章 · 获赞 0 · 访问量 9876

猜你喜欢

转载自blog.csdn.net/weixin_45399178/article/details/105053508