Criteria for Passwords
1. At least 8 characters in length.
2. Consist of only letters and digits
3. Have at least 2 digits.
Write C++ code to read from 3 files of at least 10 passwords named passwords_one.txt, passwords_two.txt, passwords_three.txt. Sort the passwords depending on if they fit the criteria listed above. If they do fit the criteria put them in a file named valid_passwords.txt then tell the console how many passwords were sorted into that file. If they don't fit the criteria put them into a folder named invalid_passwords.txt. The code can only be comprised using <fstream>, <iostream>, and the <string> header files. DO NOT us break or continue statements in your code!!
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
//function to test if its a alphanumeric character
bool isLetter(char c){
if( c >='a' && c<='z' ){
return true;
}
else if(c >='a' && c<='z' ){
return true;
}else{
return false;
}
}
//function to test if its digit
bool isDigit(char c){
if( c >='0' && c<='9' ){
return true;
}
else{
return false;
}
}
//function to test if its valid password
bool isValid(string s){
int len = s.length();
if(len<8)
return false;
int countDigit=0; //will count number of digits
found
for(int i=0;i<len;i++){
char c = s[i];
if( isLetter(c)){
}else
if(isDigit(c)){
countDigit++;
}else{
return false; // false if neither digit nor
letter
}
}
if( countDigit <2) // no two
digits or more
return false;
return true;
}
int main(){
ofstream myValidFile;
myValidFile.open("valid_passwords.txt"); //valid
password txt
ofstream myInValidFile;
myInValidFile.open("invalid_passwords.txt"); //invalid password
ifstream myReadFile1;
myReadFile2.open("passwords_one.txt");
string str;
if (myReadFile1.is_open()) {
while (std::getline(myReadFile1, str)) //read
each line of the text
{
if(isValid(str)){
//check validity
myValidFile1 << str<<endl; //add to valid
file
}
else{
myInValidFile <<
str<<endl; //add to
invalid file
}
}
}
ifstream
myReadFile2;
//again do the same for second file
myReadFile.open("passwords_two.txt");
string str;
if (myReadFile2.is_open()) {
while (std::getline(myReadFile2, str))
{
if(isValid(str)){
myValidFile << str<<endl;
}
else{
myInValidFile << str<<endl;
}
}
}
ifstream myReadFile3; // again do the same for third file
myReadFile.open("passwords_three.txt");
string str;
if (myReadFile3.is_open()) {
while (std::getline(myReadFile3, str))
{
if(isValid(str)){
myValidFile << str<<endl;
}
else{
myInValidFile << str<<endl;
}
}
}
myReadFile1.close(); // close
all the open files
myReadFile2.close();
myReadFile3.close();
myValidFile.close();
myInValidFile.close();
return 0;
}
Criteria for Passwords 1. At least 8 characters in length. 2. Consist of only letters and...
Keeping this code written as close to this as possible and only using these headers. How do I turn this in to a code that can read from 3 files of passwords then sort them into two files. One for valid passwords and the other for invalid passwords and then send a message to the user that says how many are valid and how many are invalid. Only using std::ifstream fin; fin.open("data.txt"); fin.close(); std::ofstream fout; fout.open("data.txt"); fout.close(); #include <iostream> #include...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...
You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...
You will be given several strings full of different keyboard
characters, some of which are letters of the alphabet.
Write a java program that creates a binary tree that uses
only the alphabetical characters (a-z, A-Z) as the value within the
leaf nodes using recursion and preorder traversal. All
other values within the tree (either the root node or internal
nodes) will be null. You may create any methods you see fit, so
long as the final binary tree is...
Homework 2: Avatar Cosmetic Description Use Decorator Pattern to design a command-line based avatar customization system for a game. The user shall select an avatar from two options: a male and a female. The user shall select various cosmetics for the avatar, including: Jacket T-shirt Jeans Shorts Sunglasses Running Shoes The system shall display the description of the avatar at the end of the customization. Example UI Welcome to the Avatar 1.0 System! Please select a cosmetic for your character:...
Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...
Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...
Homework 1- Merge Files: 1. Design a class named MergeFiles 1 Three file names are passed as command-line arguments to MergeFiles as follows: java MergeFiles filel file2 mergedFile II. MergeFiles reads names stored in files file and file2 III. Merges the two list of names into a single list IV. Sorts that single list V. Ignores repetitions VI. Writes the sorted, free-of-repetitions list to a new file named mergedFile.txt VII. The names in all three files are stored as one...