Si toi aussi tu es soumis à Sarbanes-Oxley, peut-être utilises-tu déjà un générateur de mot passe de qualité. Sinon, je te prête celui-ci. Je n'en dis pas plus mais c'est du vrai. Du coup les mots de passe ont tous un petit air de famille.
#define FALSE 0
#define TRUE 1
int rand ();
unsigned long getseed ();
main (int argc, char *argv[])
{
char AMin[] = "abcdefghijklmnopqrstuvwxyz";
char AMaj[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char Nume[] = "0123456789";
char Spec[] = "!:~{}.^*=+-,?_%";
long trustedhostid[2];
int istrustedhost = 0;
char PassWord[20];
int NSpec = 15;
int a = 0;
int seed, numgen, longpass, typelettre;
int FMin, FMaj, FNum, FSpe;
int ic, i, j, k, l, n;
FMin = FMaj = FNum = FSpe = FALSE;
l = 1;
#if 0
if (getuid () > 0)
{
fprintf (stderr, "Sorry, only root can run this command\n");
exit (1);
}
#endif
seed = getseed ();
while (seed <= 100000)
{
seed = getseed ();
}
longpass = 8;
numgen = fonct_rand (seed);
ic = 0;
n = numgen % 26;
if (numgen % 2 == 0)
{
PassWord[ic] = AMin[n];
FMin = TRUE;
}
else
{
PassWord[ic] = AMaj[n];
FMaj = TRUE;
}
for (ic = 1; ic < longpass; ic++)
{
seed = numgen;
numgen = fonct_rand (seed);
typelettre = numgen % 4;
if (ic > longpass / 5 && !FMin)
typelettre = 0;
if (ic > longpass * 2 / 5 && !FMaj)
typelettre = 1;
if (ic > longpass * 3 / 5 && !FNum)
typelettre = 2;
if (ic > longpass * 4 / 5 && !FSpe)
typelettre = 3;
switch (typelettre)
{
case 0:
n = numgen % 26;
PassWord[ic] = AMin[n];
FMin = TRUE;
break;
case 1:
n = numgen % 26;
PassWord[ic] = AMaj[n];
FMaj = TRUE;
break;
case 2:
n = numgen % 10;
PassWord[ic] = Nume[n];
FNum = TRUE;
break;
case 3:
n = numgen % NSpec;
PassWord[ic] = Spec[n];
FSpe = TRUE;
break;
}
}
PassWord[ic] = '\0';
printf ("%s\n", PassWord);
}
int
fonct_rand (int j)
{
int i, k, l;
l = 1;
k = j / 100000;
k *= 100000;
l = j - k;
for (i = 0; i < l; i++)
rand ();
return rand ();
}
unsigned long
getseed ()
{
unsigned int myseed;
FILE *devrandom;
if ((devrandom = fopen ("/dev/random", "r")) == NULL)
{
fprintf (stderr, "Sorry , I can't open /dev/random \n");
exit (1);
}
else
{
fread (&myseed, sizeof (myseed), 1, devrandom);
fclose (devrandom);
}
return (myseed);
}
Aucun commentaire:
Enregistrer un commentaire