Need help writing a password checker.

so I have 2 files that have passwords, one is the passwords that Im checking and one is the passwords im checking against, ive done everything up until the point where I actually have to check them, (my professor suggested a bool return function) but I cant seem to get it to work, ive been messing around for a while now but i cant even think on how to start it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

bool compare(&string[], &string[], &int);

int main(){
    
    //define ALL variables
    int passed, failed, sizeP, sizeC;
    
    string *commList, *passList, passName, commName, numPass, numCheck, temp;
    
    //prompt for names of files that will be opened
    cout << "Please enter the name of the file: ";
    cin >> passName;
    
    cout << "Please enter the name of the common passwords file: ";
    cin >> commName;
    
    
    //open files and check if they are open
    ifstream passwords;
    passwords.open(passName);
    if(!passwords){
        cout << "Error opening file" << endl;
        return 1;
    }
    
    ifstream commPass;
    commPass.open(commName);
    if(!commPass){
      cout << "Error opening file" << endl;
      return 1;
    }
    
    //get the number of passwords by seing the first value of the array
    getline(passwords, numPass);
    
    //convert it to a int
    sizeP = stoi(numPass);
    
    // make it the size of a new array
    passList = new string[sizeP];
    
    //Do the same for the other array of common passwords
    getline(commPass, numCheck);
    
    sizeC = stoi(numCheck);
    
    commList = new string[sizeC];
    
    cout << "Checked " << sizeP << " passwords in file: " << passName << endl;
    
    //enter both of these text files into the arrays
    for(int count = 0; count < sizeP; count++){
      getline(passwords, passList[count]);
      
      for(int increment = 0 && count < sizeP){
        temp = passList[increment];
        temp[increment]
      }
      
    };
    
    for(int count = 0; count < sizeC; count++){
      getline(commPass, commList[count]);
    };
    
}

bool compare (&commList[], &currentpass[], &sizep){
 
}
If I understand you correctly, you have two files with <passwords> that both look something like:

1
2
3
4
5
6
5
av7;a38v7-a
EatMoreSugar1
12345
pass
correct.horse.battery.staple

And your task is to verify that all the passwords listed in the first file also appear in the second file? (Just not necessarily in the same order?)

Are you expected to load each file as a list of strings? (As an array or vector<string>?)

It might help to move the stuff to read a file into a function, so you can load a list of strings passwords easily:

1
2
  string * passwords_to_check = load_passwords( passName, &num_passwords_to_check ); 
  string * common_passwords   = load_passwords( commName, &num_common_passwords ); 

Don’t forget to free them before your program terminates:
1
2
  delete [] common_passwords;
  delete [] passwords_to_check;


Your function to check should take a single password and check to see if it is in the common_passwords list.

1
2
3
4
bool is_it_a_password( const string & password, const string passwords[], int num_passwords )
{
  ...
}

You would call it in a loop:

1
2
3
4
5
6
7
8
9
10
11
for (int n = 0;  n < num_passwords_to_check;  n++)
{
  if (is_it_a_password( passwords_to_check[n], common_passwords, num_common_passwords ))
  {
    passed += 1;
  }
  else
  {
    failed += 1;
  }
}

You will notice I have been liberally re-naming your variables. Your variable names are difficult to read. Use names that are easy to read.
I appreciate the information and advice you have shared. I will try to figure it out for more.
https://www.dnahrblock.one/
Topic archived. No new replies allowed.