Jump to content
EleTD.com
Sign in to follow this  
Guest GoSu.SpeeD

[C/++] Random Password Generator

Recommended Posts

Guest GoSu.SpeeD

Well i didn't do this recently, but i thought I'd post it up because it's quite easy to understand, i also commented it so you should be able to understand what's going on easily

/* 
*   Random Password Generator
*   Coded By Shoxin/Akimoko/GoSu.Speed ETC.
*
* Generates a random password between 13-21 characters long ( usually )
* Generated password is saved in a newly created text document called
* passwords. Upon the next execution of the password generator,
* the new password will be stored in passwords.txt but on the next line.
*/

#include <stdio.h>
#include <windows.h>

int main()
{
    char author[MAX_PATH] = "GoSu.SpeeD";
    
    // Sets Console Title and console text color
    SetConsoleTitle("Coded By GoSu.SpeeD // Random Password Generator");
    SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_BLUE | FOREGROUND_INTENSITY );
    // Sets Console Title and console text color
    
    unsigned char c;
    int a; // for the return value of getchar()
    int d;
    int e = 40; // increase this for a longer password

    srand(GetTickCount());

    printf("\t\t Random Password Generator\n\n");  // our menu
    printf("Options:\n\n"
          "1 - Generate a password\n"
          "2 - Exit\n\n"
          ">");

    a = getchar();
    if (a == '1') // if option picked is 1
    {
        FILE *fp; // create file pointer
        fp = fopen("Passwords.txt", "a"); // open file for appending
        for (d = 0; d < e; d++) // loop what's inside, until d is equal to e
        {
            c = (rand() % 255); // 255 = Number of ASCII Codes
            
            if(isgraph(c)) // is the contents of "c" printable?
            {
                fprintf(fp, "%c", c); // write to file
            }
        }
        fprintf(fp, "\n"); // makes sure we start on the next line
        printf("\n\n");
        fclose(fp); // close file
        system("cls"); // clear console

        printf("Your generated password is now saved in Passwords.txt\n\n");

    }
    if (a == '2') // if user picks option 2
    {
        exit(1); // exit
    }
    fflush(stdin); // flush all that was caught in previous call to getchar()
    getchar(); //pause
    return 0;
}

Share this post


Link to post
Guest Jacob

Nice script... although it doesnt fully compile in codeblocks.

line 45:

            if(isgraph(c)) // is the contents of "c" printable?

Gives a build error.

If i remove that line it prints non ansi stuff, my text editor can't print... thus making a lot of rectangle's.

Share this post


Link to post
Sign in to follow this  

×
×
  • Create New...