44 lines
1.6 KiB
C
44 lines
1.6 KiB
C
|
|
#ifndef AUTHMANAGER_H
|
|||
|
|
#define AUTHMANAGER_H
|
|||
|
|
|
|||
|
|
#include <string>
|
|||
|
|
#include <ctime>
|
|||
|
|
|
|||
|
|
class AuthManager
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
// 获取机器码
|
|||
|
|
static std::string GetMachineCode();
|
|||
|
|
|
|||
|
|
// 生成授权码(带过期时间,格式yyyyMMdd)
|
|||
|
|
static std::string GenerateLicenseKey(const std::string& machineCode, const std::string& expireDate);
|
|||
|
|
|
|||
|
|
// 保存授权信息
|
|||
|
|
static bool SaveLicenseInfo(const std::string& licenseKey, const std::string& expireDate);
|
|||
|
|
|
|||
|
|
// 加载授权信息
|
|||
|
|
static bool LoadLicenseInfo(std::string& licenseKey, std::string& expireDate);
|
|||
|
|
|
|||
|
|
// 检查授权有效性
|
|||
|
|
static bool CheckLicenseValid();
|
|||
|
|
|
|||
|
|
// 验证用户输入的授权码,返回是否有效及过期日期
|
|||
|
|
static bool ValidateLicenseKey(const std::string& licenseKey, std::string& expireDate);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
static std::string GetCpuSerialNumber();
|
|||
|
|
static std::string GetDiskSerialNumber();
|
|||
|
|
static std::string ExecuteCommand(const std::string& cmd);
|
|||
|
|
static std::string MD5Hash(const std::string& input);
|
|||
|
|
static std::string EncryptString(const std::string& plainText, const std::string& key);
|
|||
|
|
static std::string DecryptString(const std::string& cipherText, const std::string& key);
|
|||
|
|
static std::string Base64Encode(const std::string& input);
|
|||
|
|
static std::string Base64Decode(const std::string& input);
|
|||
|
|
static std::string GetCurrentDate();
|
|||
|
|
static std::string GetCurrentDateTime();
|
|||
|
|
static std::string ToUpper(const std::string& str);
|
|||
|
|
static std::string GetFilePath();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif // AUTHMANAGER_H
|