Per Erik Strandberg /cv /kurser /blog

This simple C++ template generates a random password of 8 characters with alphanumeric values, f.x. bvyykru2, 73sdiop6, etc.

See also Cpp Class Template.

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

unsigned long seed_time()
{
    struct timeval t1;
    gettimeofday(&t1, NULL);
    return t1.tv_usec + (unsigned int)time(0) + (unsigned int)clock();
}

int main(int argc, char * argv[])
{
    int j = 0;
    int n = 8;
    short c;
    char ca = 'a';
    char cz = 'z';
    char c0 = '0';
    char c9 = '9';

    srand(seed_time());

    for (j = 0; j < n; j++)
    {
        c = rand()%36;
        printf("%c", (c < 10) ? (c0 + c) : (ca + c - 10));
    }
    printf("\n");

    return 0;
}


Denna sida tillhör Kategori Mallar.