auto generate password

This is a discussion on auto generate password within the C Programming forums, part of the General Programming Boards category; Hi Is there anyway to automaticlly generate password with combine of numbers and characters, alphanumeric...such as: Your Password have been ...

  1. #1
    Coconut
    Guest

    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

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    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'.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    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
    My best code is written with the delete key.

  4. #4
    Coconut
    Guest
    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 +
    +===========================================+

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Or you can try my program here .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  2. generate a random password
    By mabufo in forum C++ Programming
    Replies: 17
    Last Post: 02-23-2006, 05:57 PM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 09:42 PM
  4. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 01:13 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 01:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21