Compare commits
6 Commits
bojingchi_
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
bff006fc89 | 3 months ago |
|
|
9f77ddb378 | 3 months ago |
|
|
9c5ed8128d | 3 months ago |
|
|
e4caee3e2b | 3 months ago |
|
|
9049dfc20e | 3 months ago |
|
|
ca6ff17456 | 3 months ago |
@ -0,0 +1,16 @@
|
||||
#ifndef EMAILSENDER_H
|
||||
#define EMAILSENDER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class EmailSender {
|
||||
public:
|
||||
static bool sendVerificationCode(const std::string& email, const std::string& code);
|
||||
|
||||
private:
|
||||
static bool sendByPowerShell(const std::string& email, const std::string& code);
|
||||
static bool sendByCurl(const std::string& email, const std::string& code);
|
||||
static bool sendBySMTP(const std::string& email, const std::string& code);
|
||||
};
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@ -0,0 +1,23 @@
|
||||
#ifndef LOGINWINDOW_H
|
||||
#define LOGINWINDOW_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class LoginWindow {
|
||||
public:
|
||||
static void Show();
|
||||
static HWND GetHandle() { return hwnd; }
|
||||
|
||||
private:
|
||||
static HWND hwnd;
|
||||
static HWND hEmail;
|
||||
static HWND hPassword;
|
||||
static HWND hMessage;
|
||||
|
||||
static void CreateControls();
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static void OnLogin();
|
||||
static void OnRegister();
|
||||
};
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@ -0,0 +1,30 @@
|
||||
#ifndef REGISTERWINDOW_H
|
||||
#define REGISTERWINDOW_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
|
||||
class RegisterWindow {
|
||||
public:
|
||||
static void Show();
|
||||
static HWND GetHandle() { return hwnd; }
|
||||
|
||||
private:
|
||||
static HWND hwnd;
|
||||
static HWND hEmail;
|
||||
static HWND hCode;
|
||||
static HWND hPassword;
|
||||
static HWND hConfirmPassword;
|
||||
static HWND hMessage;
|
||||
|
||||
static std::string generatedCode;
|
||||
|
||||
static void CreateControls();
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static void OnGetCode();
|
||||
static void OnRegister();
|
||||
static void OnBack();
|
||||
static bool registerUserWithPassword(const std::string& email, const std::string& password);
|
||||
};
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
#include "User.h"
|
||||
|
||||
User::User(const std::string& email, const std::string& password, const std::string& userType)
|
||||
: email(email), password(password), userType(userType) {}
|
||||
|
||||
std::string User::getEmail() const {
|
||||
return email;
|
||||
}
|
||||
|
||||
std::string User::getPassword() const {
|
||||
return password;
|
||||
}
|
||||
|
||||
std::string User::getUserType() const {
|
||||
return userType;
|
||||
}
|
||||
|
||||
void User::setPassword(const std::string& newPassword) {
|
||||
password = newPassword;
|
||||
}
|
||||
|
||||
bool User::validatePassword(const std::string& password) const {
|
||||
return this->password == password;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class User {
|
||||
public:
|
||||
User(const std::string& email, const std::string& password, const std::string& userType);
|
||||
|
||||
std::string getEmail() const;
|
||||
std::string getPassword() const;
|
||||
std::string getUserType() const;
|
||||
void setPassword(const std::string& newPassword);
|
||||
|
||||
bool validatePassword(const std::string& password) const;
|
||||
|
||||
private:
|
||||
std::string email;
|
||||
std::string password;
|
||||
std::string userType;
|
||||
};
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@ -0,0 +1,164 @@
|
||||
#include "UserManager.h"
|
||||
#include "User.h"
|
||||
#include "EmailSender.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <windows.h>
|
||||
#include <sstream>
|
||||
|
||||
UserManager::UserManager() {
|
||||
currentUser = NULL;
|
||||
srand(static_cast<unsigned int>(time(NULL)));
|
||||
loadUsers();
|
||||
}
|
||||
|
||||
UserManager& UserManager::getInstance() {
|
||||
static UserManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool UserManager::validateEmailFormat(const std::string& email) {
|
||||
size_t atPos = email.find('@');
|
||||
size_t dotPos = email.find('.');
|
||||
return atPos != std::string::npos && dotPos != std::string::npos && atPos < dotPos;
|
||||
}
|
||||
|
||||
bool UserManager::validatePasswordFormat(const std::string& password) {
|
||||
if (password.length() < 6 || password.length() > 10) return false;
|
||||
|
||||
bool hasUpper = false, hasLower = false, hasDigit = false;
|
||||
for (size_t i = 0; i < password.length(); ++i) {
|
||||
char c = password[i];
|
||||
if (isupper(c)) hasUpper = true;
|
||||
if (islower(c)) hasLower = true;
|
||||
if (isdigit(c)) hasDigit = true;
|
||||
}
|
||||
|
||||
return hasUpper && hasLower && hasDigit;
|
||||
}
|
||||
|
||||
std::string UserManager::generateRandomCode(int length) {
|
||||
const std::string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::string code;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
code += chars[rand() % chars.size()];
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
bool UserManager::sendEmail(const std::string& email, const std::string& code) {
|
||||
// 使用EmailSender类发送邮件
|
||||
return EmailSender::sendVerificationCode(email, code);
|
||||
}
|
||||
|
||||
std::string UserManager::generateRegistrationCode(const std::string& email) {
|
||||
std::string code = generateRandomCode(6); // 6位验证码
|
||||
|
||||
// 发送邮件
|
||||
if (sendEmail(email, code)) {
|
||||
return code;
|
||||
} else {
|
||||
return ""; // 发送失败返回空字符串
|
||||
}
|
||||
}
|
||||
|
||||
bool UserManager::registerUser(const std::string& email) {
|
||||
if (isEmailRegistered(email)) return false;
|
||||
|
||||
std::string defaultPassword = "Temp123";
|
||||
users.push_back(User(email, defaultPassword, "elementary"));
|
||||
saveUsers();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UserManager::registerUserWithPassword(const std::string& email, const std::string& password) {
|
||||
if (isEmailRegistered(email)) return false;
|
||||
|
||||
// 验证密码格式
|
||||
if (!validatePasswordFormat(password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
users.push_back(User(email, password, "elementary"));
|
||||
saveUsers();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UserManager::login(const std::string& email, const std::string& password) {
|
||||
for (size_t i = 0; i < users.size(); ++i) {
|
||||
User& user = users[i];
|
||||
if (user.getEmail() == email && user.validatePassword(password)) {
|
||||
currentUser = &user;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UserManager::changePassword(const std::string& email, const std::string& oldPassword, const std::string& newPassword) {
|
||||
for (size_t i = 0; i < users.size(); ++i) {
|
||||
User& user = users[i];
|
||||
if (user.getEmail() == email && user.validatePassword(oldPassword)) {
|
||||
if (validatePasswordFormat(newPassword)) {
|
||||
user.setPassword(newPassword);
|
||||
saveUsers();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UserManager::isEmailRegistered(const std::string& email) {
|
||||
for (size_t i = 0; i < users.size(); ++i) {
|
||||
const User& user = users[i];
|
||||
if (user.getEmail() == email) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UserManager::loadUsers() {
|
||||
std::ifstream file("data/users.txt");
|
||||
if (!file) return;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
size_t pos1 = line.find(',');
|
||||
size_t pos2 = line.find(',', pos1 + 1);
|
||||
|
||||
if (pos1 != std::string::npos && pos2 != std::string::npos) {
|
||||
std::string email = line.substr(0, pos1);
|
||||
std::string password = line.substr(pos1 + 1, pos2 - pos1 - 1);
|
||||
std::string userType = line.substr(pos2 + 1);
|
||||
|
||||
users.push_back(User(email, password, userType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserManager::saveUsers() {
|
||||
// 创建数据目录
|
||||
CreateDirectory("data", NULL);
|
||||
|
||||
std::ofstream file("data/users.txt");
|
||||
for (size_t i = 0; i < users.size(); ++i) {
|
||||
const User& user = users[i];
|
||||
file << user.getEmail() << "," << user.getPassword() << "," << user.getUserType() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
User* UserManager::getCurrentUser() {
|
||||
return currentUser;
|
||||
}
|
||||
|
||||
void UserManager::logout() {
|
||||
currentUser = NULL;
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
? 成功发送验证码到: 3675658020@qq.com | 验证码: OP9R0N | 时间: 22:45:10
|
||||
? 成功发送验证码到: 3675658020@qq.com | 验证码: B3XMEI | 时间: 22:45:10
|
||||
? 成功发送验证码到: 3675658020@qq.com | 验证码: BG5ZSN | 时间: 22:45:10
|
||||
@ -0,0 +1,13 @@
|
||||
=== 邮件发送记录 ===
|
||||
时间: Oct 7 2025 23:35:05
|
||||
方案: PowerShell
|
||||
发件人: 3675658020@qq.com
|
||||
收件人: 2470975401@qq.com
|
||||
验证码: ZH4RXI
|
||||
执行结果: 正在发送邮件到: 2470975401@qq.com
|
||||
验证码: ZH4RXI
|
||||
邮件发送成功!
|
||||
SUCCESS
|
||||
|
||||
=========================
|
||||
|
||||
Loading…
Reference in new issue