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

int generate_random_number(int min, int max)
{
    return min + rand() % (max - min + 1);
}

int main()
{
    char upperCase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char lowerCase[] = "abcdefghijklmnopqrstuvwxyz";
    char special[] = "!@#$%^&*";
    int length;

    printf("Enter the length of your password: ");
    scanf("%d", &length);

    char pass[length + 1];

    srand(time(NULL));

    for (int i = 0; i < length; i++)
    {
        int type = generate_random_number(0, 2);
        if (type == 0)
        {
            int randomIndex = generate_random_number(0, 25);
            pass[i] = upperCase[randomIndex];
        }
        else if (type == 1)
        {
            int randomIndex = generate_random_number(0, 25);
            pass[i] = lowerCase[randomIndex];
        }
        else
        {
            int randomIndex = generate_random_number(0, 7);
            pass[i] = special[randomIndex];
        }
    }

    // Null-terminate the string
    pass[length] = '\0';

    printf("Your created password is: %s\n", pass);
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: