Question

Please help with writing this code. The language is C++. I'm using vim. 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: letters upper case lower case *numbers 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 AtCde 1z254 (either would be acceptable passwords) Would you like to create another password (0-no, 1-yes)? 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>
#include <string>
#include <ctime>
using namespace std;

string randomString(int length, string charIndex){
int ri[length];
for (int i = 0; i < length; ++i){
ri[i] = rand() % charIndex.length();
}
string rs = "";
  
for (int i = 0; i < length; ++i){
rs += charIndex[ri[i]];
}
if (rs.empty()) randomString(length, charIndex);
else return rs;
}

int main()
{
srand(time(NULL));
int length;
int lettersConfirm;
int uppercaseLettersConfirm;
int lowercaseLettersConfirm;
int numbersConfirm;
string finalString="";
cout << "How long do you want the password be: ";
cin >> length;
cout << "Do you want letters (0-No, 1-Yes)? ";
cin >> lettersConfirm;
if(lettersConfirm == 1){
cout << "Do you want uppercase letters (0-No, 1-Yes)? ";
cin >> uppercaseLettersConfirm;
if(uppercaseLettersConfirm == 1){
cout << "How many characters should be upper case?";
int uppercaseCharNum;
cin >> uppercaseCharNum;
finalString += randomString(uppercaseCharNum,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
cout << "Do you want lowercase letters (0-No, 1-Yes)? ";
cin >> lowercaseLettersConfirm;
if(lowercaseLettersConfirm == 1){
cout << "How many characters should be lower case?";
int lowercaseCharNum;
cin >> lowercaseCharNum;
finalString += randomString(lowercaseCharNum,"abcdefghijklmnopqrstuvwxyz");
}
  
  
}
cout << "Do you want numbers (0-No, 1-Yes)? ";
cin >> numbersConfirm;
if(numbersConfirm == 1){
cout << "How many characters should be number?";
int numbersCharNum;
cin >> numbersCharNum;
finalString += randomString(numbersCharNum,"0123456789");
}
  
cout << "Your random password is: " << finalString << endl;
}

Output:

How long do you want the password be:  10
Do you want letters (0-No, 1-Yes)?  1
Do you want uppercase letters (0-No, 1-Yes)?  1
How many characters should be upper case? 3
Do you want lowercase letters (0-No, 1-Yes)?  1
How many characters should be lower case? 3
Do you want numbers (0-No, 1-Yes)?  1
How many characters should be number? 4
Your random password is: BBRiae9089
Add a comment
Know the answer?
Add Answer to:
Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. You are making a new account on your favorite social media website. This great new...

    2. You are making a new account on your favorite social media website. This great new website offers the most fun way to steal all of your personal information! Long story short, you need a new password. ords can include upper-case letters, lower-case letters, numbers and the symbols you can r. Characters may be repeated. Please do not simplify your answers. get by holding Shift + a numbe (a) Suppose you want to make a 7, 8 or 9-character long...

  • Homework: Homework 11.6 - 11.9 Score: 0 of 1 pt + 9 of 22 (1 complete)...

    Homework: Homework 11.6 - 11.9 Score: 0 of 1 pt + 9 of 22 (1 complete) 11.7.27 A three-character password to log onto a computer is drawn from the digits 0-9 and a subset of 18 letters of the alphabet (repetition is permitted). Determine the number of passwords possible it a) the letters used are not case sensitive (that is a lowercase letter is treated the same as an uppercase letter) b) the letters used are case sensitive (that is,...

  • Compute the number of passwords of each type below along with how long it would taketo...

    Compute the number of passwords of each type below along with how long it would taketo test all possible such passwords if it takes 1 nanosecond to test a password. Report the times in the most convenient human understandable form. In all of these, unless noted otherwise, order matters and repetition of characters is allowed. Passwords of length 8 with any combination of lowercase letters, uppercase letters,and numbers. Passwords that start with a capital letter, have 10 lowercase letters, and...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE...

    JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE Below is the program -- fill the code as per the instructions commented: //---------------------------------------------------------------------------------------------------------------------------------------------------------------// /* The idea of this HW is as follows : A password must meet special requirements, for instance , it has to be of specific length, contains at least 2 capital letters , 2 lowercase letters, 2 symbols and 2 digits. A customer is hiring you to create a class...

  • Please do question 19 and 27. Please show all work 19) A) How many different area...

    Please do question 19 and 27. Please show all work 19) A) How many different area code 909 telephone numbers are possible? Assume that the first digit of any phone number cannot be 0 or 1. ) B) Suppose a computer requires eight characters for a password. The first three characters must be letters and the remaining five characters must be numbers. How many passwords are possible? 27) In how many ways can 8 people be arranged for a photograph...

  • I just started working on some code for a password creator. I was doing some testing and I keep g...

    I just started working on some code for a password creator. I was doing some testing and I keep getting this error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47) at java.base/java.lang.String.charAt(String.java:693) at PasswordCreater.check(PasswordCreater.java:56) at Password.main(Password.java:23 In my code I am having the user create a password that is at least 6 characters long, but no more than 16. Also, include at least one lowercase letter, one uppercase letter, one number digit and one special...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • Problem Statement In genetics, most large animals have two copies of every gene, one from each...

    Problem Statement In genetics, most large animals have two copies of every gene, one from each parent. In the simplest genetic model, each of the genes takes on one of two forms, usually represented by an uppercase and lowercase letter of the same value ('A' and 'a', for example). The pair of genes typically contributes to the external qualities of the animal in one of two ways. If both genes are uppercase, they contribute in one way, while if both...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT