Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this lab, I have to make password generator, The rules are in t

ID: 3589388 • Letter: I

Question

I need help with this lab, I have to make password generator, The rules are in the pdf file, thanks.

Problem Statement A good password has many requirements. Humans have a hard time meeting these requirements left to their own devices. You are tasked with creating a program that will generate a password based on what the user wants in the password. The user should be able to choose if they want a password with: upper case lower case The user should also provide the length of the password and how much of the password should be comprised of their selections. You can generate in order or out of order (see below). For example: Welcome to Password Creator! How long do you want the password to be? 10 Do you want letters (0-no, 1-yes)? 1 Do you want uppercase letters (0-no, 1-yes)? 1 How many characters of the password should be uppercase? 2 Do you want lowercase letters (0-no, 1-yes)? 1 How many characters of the password should be lowercase?4 Do you want numbers (0-no, 1-yes)? 1 How many characters of the password should be numbers?4 Your random password is: ACbzdf1254 or AtCde1z254 (either would be acceptable passwords) Would you like to create another password (0-no, 1-yes)?0 You need to generate characters and numbers for the password length specified by the user Therefore, you need a way to repeat generating random numbers and characters. You could use a while loop, but it would be more appropriate to use a for loop. For example: for(int i=0; i

Explanation / Answer

package test1;

import java.util.Random;

import java.util.Scanner;

public class test1 {

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            int length = 0, letterFlag = 0, upperCaseLetterFlag = 0, upperCaseLength = 0, lowerCaseLetterFlag = 0,

            lowerCaseLength = 0, numberFlag = 0, numberLength = 0;

           

            Scanner sc=new Scanner(System.in);

            System.out.println("How long you password to be : ");

        length=sc.nextInt();

       

        System.out.println("Do you want letters(0-no, 1-yes) : ");

        letterFlag = sc.nextInt();

        if(letterFlag==1){

            System.out.println("Do you want uppercase letters (0-no, 1-yes) : ");

            upperCaseLetterFlag = sc.nextInt();

            if(upperCaseLetterFlag==1){

                  System.out.println("How many characters of the password should be uppercase : ");

                  upperCaseLength = sc.nextInt();

            }

            System.out.println("Do you want lower letters (0-no, 1-yes) : ");

            lowerCaseLetterFlag = sc.nextInt();

            if(lowerCaseLetterFlag==1){

                  System.out.println("How many characters of the password should be lowercase : ");

                  lowerCaseLength = sc.nextInt();

            }  

        }

       

        System.out.println("Do you want number(0-no, 1-yes) : ");

        numberFlag = sc.nextInt();

        if(numberFlag==1){

            System.out.println("How many characters of the password should be numbers : ");

            numberLength = sc.nextInt();

        }

       

            String capital_letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            String small_letter = "abcdefghijklmnopqrstuvwxyz";

            String numbers = "0123456789";

           

            do{

                  Random random = new Random();

                  char[] password_upper_case = new char[upperCaseLength];

                  for (int i = 0; i < upperCaseLength; i++)

              {

                        password_upper_case[i] = capital_letter.charAt(random.nextInt(capital_letter.length()));

              }

                 

                 

                  char[] password_lower_case = new char[lowerCaseLength];

                  for (int i = 0; i < lowerCaseLength; i++)

              {

                        password_lower_case[i] = small_letter.charAt(random.nextInt(small_letter.length()));

              }

                 

                 

                  char[] password_number = new char[numberLength];

                  for (int i = 0; i < numberLength; i++)

              {

                        password_number[i] = numbers.charAt(random.nextInt(numbers.length()));

              }

                 

                  String temp_password = String.valueOf(password_upper_case) + String.valueOf(password_lower_case) +

                              String.valueOf(password_number);

                  char[] password = new char[temp_password.length()];

                  for (int i = 0; i < temp_password.length(); i++)

              {

                        password[i] = temp_password.charAt(random.nextInt(temp_password.length()));

     

              }

                 

                  System.out.println("Your Random Password is : " + String.valueOf(password));

                  System.out.println("Would you like to create another password (0-no, 1-yes) : ");

            }while(sc.nextInt()==1);

      }

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++

Please find code in C++ as well :

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//============================================================================

// Name : test.cpp

// Author :

// Version :

// Copyright : Your copyright notice

// Description : Hello World in C++, Ansi-style

//============================================================================

#include <iostream>

#include <string>

#include <algorithm>

#include <stdlib.h>

using namespace std;

int main()

{

int length = 0, letterFlag = 0, upperCaseLetterFlag = 0, upperCaseLength = 0, lowerCaseLetterFlag = 0,

lowerCaseLength = 0, numberFlag = 0, numberLength = 0;

cout << "How long you password to be : " << endl ;

cin >> length;

cout << "Do you want letters(0-no, 1-yes) : " << endl ;

cin >> letterFlag;

if(letterFlag==1){

cout << "Do you want uppercase letters (0-no, 1-yes) : " << endl ;

cin >> upperCaseLetterFlag;

if(upperCaseLetterFlag==1){

cout << "How many characters of the password should be uppercase : " << endl ;

cin >> upperCaseLength;

}

else if(upperCaseLetterFlag==0){} else{cout<<"Wrong value. Hence exiting"; exit(0);}

cout << "Do you want lower letters (0-no, 1-yes) : " << endl;

cin >> lowerCaseLetterFlag;

if(lowerCaseLetterFlag==1){

cout << "How many characters of the password should be lowercase : " << endl ;

cin >> lowerCaseLength;

}

else if(lowerCaseLetterFlag==0){} else{cout<<"Wrong value. Hence exiting"; exit(0);}

}

else if(letterFlag==0){} else{cout<<"Wrong value. Hence exiting"; exit(0);}

cout << "Do you want number(0-no, 1-yes) : " << endl ;

cin >> numberFlag;

if(numberFlag==1){

cout << "How many characters of the password should be numbers : " << endl ;

cin >> numberLength;

}

else if(numberFlag==0){} else{cout<<"Wrong value. Hence exiting"; exit(0);}

int flag = 0;

do{

flag = 0;

string capital_letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string small_letter = "abcdefghijklmnopqrstuvwxyz";

string numbers = "0123456789";

string password = "";

if(upperCaseLength != 0){

//random_shuffle function does the shuffling

random_shuffle(capital_letter.begin(),capital_letter.end());

password = password + capital_letter.substr(0,upperCaseLength);

}

if(lowerCaseLength != 0){

random_shuffle(small_letter.begin(),small_letter.end());

password = password + small_letter.substr(0,lowerCaseLength);

}

if(numberLength != 0){

random_shuffle(numbers.begin(),numbers.end());

password = password + numbers.substr(0,numberLength);

}

if(password.length() != 0){

random_shuffle(password.begin(),password.end());

}

cout << "Your Random Password is : " << password << endl;

cout << "Would you like to create another password (0-no,1-yes) : " << endl;

cin >> flag;

}while(flag==1);

return 0;

}