[C++] Random Password Generator

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

ZionHD

Leader
Retired Staff
Nov 8, 2014
184
215
53
This scripts purpose is to randomly generate a password for you, but you set the length limit of the password.

Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

/*
* General purpose of this program is to generate a password for you.
* Created by ZionHD
* Copyright (c) 2015 Console-Forums
*/

using namespace std;

char genChar(); // Selects a random character from array

int main()
{
    srand(time(0));
    int length;
   
    // Asks user for the length of which they want there password
    cout << "Length of password: ";
    cin >> length;
   
    // For loop, keeps looping until i = length of password user wants.
    for (int i = 0; i < length; i++)
    {
        cout << genChar(); // Displays character that is randomly selected.
    }
   
    // Alerts the user that the password was generated!
    cout << "\nYour password has been generated!" << endl;
   
    return 0;

}

char genChar()
{
    // Array of characters to use
    const char pass[] =
    "0123456789"
    "!@#$%^&*"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "abcdefghijklmnopqrstuvwxyz";
   
    // Gets the size of variable pass
    int length = sizeof(pass) - 1;
   
    return pass[rand() % length];
}
 
General chit-chat
Help Users
  • @ lurch6661:
    we need more people in chat
  • @ lurch6661:
    maybe if cc hosts contests
  • @ lurch6661:
    to win premium memberships
  • @ QM|T_JinX:
    if there isnt that mutch already working ids online then yea
  • @ lurch6661:
    i mean theres gotta be a way to popularize
  • @ lurch6661:
    this site
  • @ QM|T_JinX:
    think there will be more online is when the jb on ps4 starts running
  • @ QM|T_JinX:
    not everybody have a ps5 and ps4 need low fw ps4 on lowfw is hard to find
  • @ lurch6661:
    yea that is very true
  • @ lurch6661:
    iam sure if my name was illuminated we could get more followers for cc
  • @ lurch6661:
    i forget how much it is
  • @ QM|T_JinX:
    not sure
  • Chat Bot:
    extiflyy is our newest member. Welcome!
  • @ lurch6661:
    my minds playing tricks on me
  • @ lurch6661:
    lol
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    viejo loco is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    jaywill32 is our newest member. Welcome!
  • Chat Bot:
    iShatOnU__ has left the room.
  • Chat Bot:
    Chat Bot: abdul123 has started a new thread called "Premier Сasual ****** - Verified Females" in General...