Мне поручено создать решение, которое будет генерировать безопасный пароль для пользователя. мне нужно ...Ранжирование массива символов для отображения случайного пароля
Подскажите пользователю на длину пароля, количество специальных символов вместе с количеством цифр.
Пароль должен генерироваться случайным образом с использованием этих входов.
, например, выход:
Что длина пароля? 8
Сколько специальных символов? 2
Сколько номеров? 2
Ваш пароль: aun2 $ 1s #
Мой уровень программирования находится на стадии новичка здесь и пример того, что я сделал до сих пор
#include <iostream>
#include <algorithm>
using namespace std;
void WorkoutPass(int ,int,int);
int passlength;
int specChar;
int number;
int main()
{
cout << "Enter the length of password: ";
cin >> passlength;
if (passlength > 0)
{
cout << "Enter the amount of special characters: ";
cin >> specChar;
if (specChar > passlength)
{
cout << "Error - invalid value entered is above the length of password";
}
cout << "Enter amount of numbers";
cin >> number;
if (number > passlength)
{
cout << "Error - invalid value entered is above the length of password";
}
WorkoutPass(passlength, specChar, number);
}
else
{
cout << "Error - invalid value entered password must be above zero";
}
return 0;
}
void WorkoutPass(int p, int s, int n)
{
string password;
char alphaBetArray[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char specCharArray[10] = {'!','£','$','%','&','@','~','#','>','<'};
char numberArray[10] = {'1','2','3','4','5','6','7','8','9','10'};
int numberOfLetters = p - s - n;
char letter;
// generate (numberOfLetters) letters
// each letter generated we add to the string
password += letter;
// Add special characters
// Add numbers
random_shuffle(password.begin(), password.end());
cout << password.c_str() << endl;
}
void DisplayPass()
{
}
'' 10'' является юкки. Вы имели в виду ''0''? – Bathsheba
да, извините, просто обратите внимание, что – Cerberus
@Bathsheba Кстати, '£' также является широким персонажем, поэтому в зависимости от вашего языка, который, вероятно, тоже должен быть заменен. –