Генератор паролей C++

Живой_мертвый

Кислотный дом
Joined
Aug 8, 2018
Messages
142
Reaction score
22
Пароль (фр. parole — слово) — условное слово[1] или набор знаков, предназначенный для подтверждения личности или полномочий.
Пароли часто используются для защиты информации от несанкционированного доступа. В большинстве вычислительных систем комбинация «имя пользователя — пароль» используется для удостоверения пользователя.

Wikipeadia

Сижу значит решаю олимпиадные задачи по c++, и приходит идея сделать генератор паролей. Почему бы и нет?

C++:
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stdlib.h>
#include <fstream>

using std::cout;
using std::cin;
using std::endl;

class PassGen {

public:
    void displayMessage()
    {
        int passLenght;
        int numOfPasswords;
        char * filename = new char;

        cout << "Введите длину пароля для генерации: ";
        cin >> passLenght;
        cout << "Введите количество паролей для генерации: ";
        cin >> numOfPasswords;
        cout << "Будет сгенерировано паролей: " << numOfPasswords << "." << endl;
        cout << endl;
        cout << "Введите имя файла для записи: ";
        cin >> filename;

        std::ofstream outFile(filename);

        for (int k = 0; k < numOfPasswords; k++) {
            for (int i = 0; i < passLenght; ++i) {   
                numOfChars(passLenght);
                passGenerator(passLenght);
                outFile << password [i];
            }
            outFile << endl;
        }
        outFile.close();

        cout << "Пароли успешно сгенерированы и записаны в файл " << filename << "" << endl;
    }

    void passGenerator(int passLenght)
    {
        password = new char [passLenght];

        for (int i = 0; i < numOfNumbers; ++i) {
            password [i] = char(rand() % 10 + 48);
        }
        for (int i = numOfNumbers; i < numOfNumbers + numOfBigChars; ++i) {
            password [i] = char(rand() % 26 + 65);
        }
        for (int i = numOfNumbers + numOfBigChars; i < passLenght; ++i) {
            password [i] = char(rand() % 26 + 97);
        }
         std::random_shuffle(password, password + passLenght);       
    }

    void numOfChars(int passLenght)
    {
        numOfSmallChars = rand() % passLenght;
        int charRandEnd = passLenght - numOfSmallChars;
        numOfBigChars = rand() % charRandEnd;
        numOfNumbers = passLenght - numOfSmallChars - numOfBigChars;
    }

private:
    int numOfSmallChars;
    int numOfBigChars;
    int numOfNumbers;
    char * password;
};

int main()
{
    setlocale(LC_ALL, "Russian");
    srand(time(NULL));
    PassGen * pass = new PassGen;
    pass->displayMessage();
    return 0;
}

View attachment 8424

View attachment 8425

View attachment 8426

Exe.файл и просто код
 

letunsy

New member
Joined
Jun 10, 2020
Messages
2
Reaction score
0
"Hey, I think you'll want to check out the 'dev/random' library for generating secure passwords in C++. It's been around for a while, but it's still a solid option for producing cryptographically secure random numbers."
 

Pilat84kz

New member
Joined
May 26, 2008
Messages
4
Reaction score
0
"Yo, I think you can do this in a simpler way without C++. Just use a library like cryptopp or OpenSSL for secure password generation. Or you can even use something like pwgen for linux, it's super easy to use."
 

Gercules

New member
Joined
Apr 29, 2011
Messages
4
Reaction score
0
I'm not really an expert in C++ programming but I think there's a library called 'cpp-passwordGenerator' that can help you create secure passwords in C++. Has anyone else used it before and what's your experience like?
 
Top