Please help me with code

Hi, so I'm having trouble with my program that validates a user's password can you please help me?
this are the problems im having so far:
I keep getting strong password even though its not a strong password. The code is through lines 59 - 100
Im also having trouble on line 163 if(userresponse.find_first_of("@%?&")) its not working, I want the program to check if the password the user inputs has one of those special characters.


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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include<iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
bool checker (string passwords[],string userresponse); // prototype common password
bool lengthcheck (string userresponse);  //checks legnth is not less than 8
bool numbercheck(string userrespnse);    //checks for number
bool charactercheck(string userresponse); // checks for character
bool uppercheck(string userresponse); // checks for uppercase letter
bool alphacheck(string userresponse); //checks alpha

int main()
{
//varriable
int count = 0;
string passwordlist [4000];
string userresponse;
string result;
 
 ifstream infile ("passwords.txt"); //open
 
   if(! infile)
   {
        cout<< " error opening file " <<endl; // identifies if if file opens properly
        exit(1);
   }
 
  
   while(!infile.eof())
 {
        infile>> passwordlist[count] ;
 
        count++;
 }
  cout<<endl;
  //rules and intro
   cout<< "Your password must contain the following: "<<endl;
   cout<<"  *The password must be at least 8 characters long."<<endl;
   cout<<"  *The password must contain at least one alpha character [a-zA-Z]."<<endl;
   cout<<"  *At least one numeric character [0-9]."<<endl;
   cout<<"  *One special character from this set: @ % ? &"<<endl;
   cout<< "-------------------------------------------------------------------"<<endl;
   cout<<"Please enter a possible password: ";
   cin>> userresponse;
   //cout << userresponse.find_first_of("@%?&") << endl;
   cout<<endl;
   cout <<"-------------------------------------------------------------------"<<endl;
   cout<<"Results: "<<endl;
 
   checker(passwordlist, userresponse); // calling function
   lengthcheck(userresponse);
   numbercheck(userresponse);
   charactercheck(userresponse);
   uppercheck(userresponse);
   alphacheck(userresponse);
  
  
   if ( bool checker  = false)   // password strong outcome 
   {
    if(bool lengthcheck = true)
    {
     if(bool numbercheck = false)
     {
      if(bool charactercheck = false)
      {
       if(bool alphacheck = true)
       {
        if(bool uppercheck = false)
        cout<< "Weak password\n";
       return true;
	   }}}}}
    if ( bool checker  = true)   // password medium outcome 
   {
    if(bool lengthcheck = true)
    {
     if(bool numbercheck = true)
     {
      if(bool charactercheck = false)
      {
       if(bool alphacheck = true)
       {
        if(bool uppercheck = true)
        cout<< " Medium password\n";
       return true;
	   }}}}}
     if ( bool checker  = true)   // password weak outcome 
   {
    if(bool lengthcheck = true)
    {
     if(bool numbercheck = true)
     {
      if(bool charactercheck = true)
      {
       if(bool alphacheck = true)
       {
        if(bool uppercheck = true)
        cout<< "Strong password\n";
       return true;
	   }}}}}
  
   return 0;
}
 
bool checker (string passwordlist[],string userresponse)
 {
 
//variables
 int i;
 bool x = false;
 
    for(i=0;i<4000;i++)
    {
 
         if (userresponse == passwordlist[i])
             {
                x= true;
             }
 
    }
         if( x ==true)
              cout<< "[X] This is a commonly used password. "<<endl;
         else
             cout<< "This password is good." << endl;
   return true;
}
bool lengthcheck(string userresponse)
{
 //variables
 int minsize = 8;
 
 
 if(userresponse.size()>= minsize)
  {
     cout<< "Password length is good."<<endl;
  
  }
 else
     cout<<"[X] The password is less than 8 charcaters."<<endl;
  return true;
}
bool numbercheck(string userresponse)
{
 int j;
 bool num = false;
 
 for (j=0;j<userresponse.length();j++)
         if(isdigit(userresponse[j]))
 {
  num = true;
 }
 if(num==true)
  cout<<"Password contains at least 1 digit."<<endl;
 else
  cout<<"[X] Password does not contain a digit."<<endl;
 return true;
}
bool charactercheck(string userresponse)
{
    int i;
    bool chara = false;
   
    if(userresponse.find_first_of("@%?&"))
      {
         chara = true;
      }
       if(chara==true)
         {
             cout<< "Password contains a character."<<endl;
         }
        else
           cout<<"[X] Password does not contain a character."<<endl;
    return true;
}
bool uppercheck(string userresponse)
{
    int j;
    bool Upper = false;
     for (j=0;j<userresponse.length();j++)
         if(isupper(userresponse[j]))
            {
                 Upper = true;
             }
             if(Upper==true)
                 {
                     cout<< "This password contains an uppercase character"<<endl;
                 }
             else
                    cout<< "[X] Password does not contain an uppercase character."<<endl;
 return true;
}
bool alphacheck(string userresponse)
{
  int j;
  bool Upper = false;
  
  for (j=0;j<userresponse.length();j++)
   if(isalpha(userresponse[j]))
             {
                 Upper = true;
             }
   
    if(Upper==true)
                 {
                     cout<< "This password contains an alpha character"<<endl;
                 }
                else
                    cout<< "[X] Password does not contain an alpha character."<<endl;
 
return true;
}
 

closed account (S6k9GNh0)
You should listen to your compiler:
http://liveworkspace.org/code/1CVPYV$0
Topic archived. No new replies allowed.