Thread: random password generator

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26

    random password generator

    Hi, I am new to C and I am trying to write a program that will take in regular easy to remember passwords like 'JohnDoe' and encrypt them with random characters. This is what I have so far:
    //passGen.c
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int main(void) {
        int length = 8;
        int r,i;
        char c;
        srand((unsigned int)time(0)); //Seed number for rand()
        for(i=0;i<length; i++) {
            r = rand() + 33;
            c = (char)r;
            printf("%c",c);
        }
    }
    To run it in Linux/Unix do ./a.out or a.out passGen JohnDoe
    The program works just the way I want it to, except I would like to narrow down the types of characters it uses. How would I modify it to only use 'normal' English letters (both upper and lower case,) numbers and only the additional characters ^, #, $ and @ for encryption? Also, I want to keep the integer length the same.
    Last edited by cDev; 07-06-2006 at 08:12 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  2. Testing Random Number Generator
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 08-12-2005, 12:48 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 08:10 AM
  5. Random Password Generator v1.0 - download it
    By GaPe in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-18-2002, 01:27 AM