help stuck!

Did this real quick there is an error, because no matter what password i enter it always says that its a common password!?  Can anyone see the error?? thanks!

/*This is in c++ by the way, the text file is in this link (https://bbhosted.cuny.edu/bbcswebdav/pid-15730817-dt-content-rid-51332648_1/courses/CSI01_CSC_211_D001_1142_1/passwordsUpdated.txt) i saved it as a .txt file 

Write a program to detect common passwords.

Read in the given file into an array of string objects (allow for 4000 entries).

Then read passwords from a user and call a function (that you write) to return whether the password is common or not.

*/

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

bool search(string commonPasswords[],string userPass,int count);

int main(){

const int MAX = 4000;
string commonPasswords[MAX];
int i = 0;
int count = 0;
string userPass;
bool found = false;
count = i;

//make cin equivalent to take in data file
ifstream infile;

//open the file
infile.open(“C:\\Users\\brian\\Desktop\\passwordsUpdated.txt”);

//check if file exists
if(!infile){
cout<<“your file doesn’t exist! “;
return 1;
}

//read in file using a while loop with an eof marker
while(!infile.eof()){

infile>>commonPasswords[i];
i++;
}
count = i;

//read in password from user
cout<<“Enter a password please…\n”;
cin>>userPass;

//function call
found = search(commonPasswords,userPass, count);
if(!found)
cout<<“Your password is too common, try again! \n”;
else
cout<<“Good password! \n”; 

return 0;
}

 

bool search(string commonPasswords[], string userPass, int count){

int j = 0;
for(j=0; j<count; j++){
if(userPass == commonPasswords[j])
return true;
}
return false;
}

 

Advertisements

One thought on “help stuck!

  1. won says:

    It was the (!found), which should have been just found oops!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: