-
auto generate password
Hi
Is there anyway to automaticlly generate password with combine of numbers and characters, alphanumeric...such as:
Your Password have been assigned: XvM23zY44CHoe
I have try random function but it generate only numbers, not
characters.
Your help would be appreciated
Coconut
-
What you could do is write a function that generates integers values in the appropriate ranges for ASCII.
IOW, if it generates 49, then cast it to a char and you'll have '1'.
-
Try using rand on an array of valid items for the password:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define len (sizeof valid / sizeof valid[0])
int main ( void )
{
int i;
const char valid[] =
"1234567890abcdefghijklmnopqrstu"
"vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
srand ( (unsigned)time ( NULL ) );
for ( i = 0; i < 8; i++ )
fputc ( valid[rand() / ( RAND_MAX / len )], stdout );
fputc ( '\n', stdout );
return 0;
}
-Prelude
-
Quote:
Originally posted by Prelude
Try using rand on an array of valid items for the password:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define len (sizeof valid / sizeof valid[0])
int main ( void )
{
int i;
const char valid[] =
"1234567890abcdefghijklmnopqrstu"
"vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
srand ( (unsigned)time ( NULL ) );
for ( i = 0; i < 8; i++ )
fputc ( valid[rand() / ( RAND_MAX / len )], stdout );
fputc ( '\n', stdout );
return 0;
}
-Prelude
Wow, that's very qwick help. Thank you
Coconut
+===========================================+
+Prelude is my favorite guru. No one on the earth like Prelude +
+===========================================+
-
Or you can try my program here :cool:.