C++小助手1.0.4

拖更原因

CSP复赛(可能这是10月26日前最后一更了……)

小助手代码

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>

using namespace std;

// 显示带有动画效果的文本
void ccc(const string &s)
{
	for (int i = 0; i < s.size(); i++)
	{
		cout << s[i];
		Sleep(50);
	}
	cout << endl;
}

// 加密字符串(简单的移位加密)
string encrypt(string str, int shift = 4)
{
	for (int i = 0; i < str.size(); i++)
	{
		str[i] += shift;
	}
	return str;
}

// 解密字符串
string decrypt(string str, int shift = 4)
{
	for (int i = 0; i < str.size(); i++)
	{
		str[i] += shift;
		if (str[i] > '9')
			str[i] = 0;
	}
	return str;
}

// 保存用户名和密码到文件
void saveUser(const string &username, const string &password)
{
	ofstream file("users.txt", ios::app);
	if (file.is_open())
	{
		file << username << " " << encrypt(password) << endl;
		file << "已经经过加密!";
		file.close();
	}
	else
	{
		ccc("无法打开用户文件进行写入!请检查文件权限或磁盘空间。");
	}
}

// 检查用户名和密码是否存在并正确
bool authenticateUser(const string &username, const string &password)
{
	ifstream file("users.txt");
	if (!file.is_open())
	{
		ccc("无法打开用户文件进行读取!请检查文件是否存在或权限是否正确。");
		return false;
	}

	string savedUsername, savedPassword;
	while (file >> savedUsername >> savedPassword)
	{
		if (savedUsername == username && savedPassword == encrypt(password))
		{
			return true;
		}
	}
	return false;
}

// 检查用户名是否已存在
bool isUsernameExists(const string &username)
{
	ifstream file("users.txt");
	if (!file.is_open())
	{
		return false;
	}

	string savedUsername, savedPassword;
	while (file >> savedUsername >> savedPassword)
	{
		if (savedUsername == username)
		{
			return true;
		}
	}
	return false;
}

// 注册新用户
void registerUser()
{
	string username, password;
	ccc("请输入要注册的用户名:");
	cin >> username;
	while (isUsernameExists(username))
	{
		ccc("该用户名已存在,请重新输入。");
		cin >> username;
	}
	while (true)
	{
		ccc("请输入要注册的密码:");
		char ch;
		password = "";
		while ((ch = _getch()) != '\r')
		{
			if (ch == '\b')
			{
				if (!password.empty())
				{
			
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值