I am in the process of programming a password manager(for educational purposes only!) in C++. To generate the master key, my program will run the previously inputed master password through the password hashing function argon2 to generate a master key. I have 1 problem. I need a way to generate salt for use with that hash function. From my previous research(Google search: "generate salt c++", and searching StackOverflow), I have seen people do various things similar to this:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(alphanum) - 1;
char genRandom() // Random string generator function.
{
return alphanum[rand() % stringLength];
}
int main()
{
srand(time(0));
for(int z=0; z < 21; z++)
{
cout << genRandom();
}
return 0;
}
My question is: Will generating a random string with rand() be enough, or is there a more accepted method of generating salt, or a library that can do it for me?
P.S When I searched StackOverflow, I could really only find articles on PHP and C#.