help with calling the function to validate

In the program i have to ask the user to input a password that contains:
-at least 6 characters in length
-must contain at least one uppercase letter and at least one lowercase letter
-must contain at least one digit
i need help with calling the function to validate the password a user would enter
this is the logic i have for it

/*
main{
need to take a string
call a function (validate) that returns valid/notvalid
if valid: display password accepted
if invalid: ask user to try again
keep a count of how many invalid attempts the user tried
if 3 times or more, terminate the program
if less than 3 times, prompt againyh6t4
}

bool validate(char* vpassword){
int length =0;
bool bool6, boollc, booluc, boold;
check if length is > 6
for(int i=0; i<20; i++)
{
if (vpassword[i] != '\0')
{
length = length +1;
}
}
if (length <6)
{
bool6 = 1;
}

check if there is lower case
islower

check if there is upperacase
isupper

check if there is a digit

1
2
3
4
5
6
7
for(int i=0; i<20; i++)
{
    if (vpassword[i] != '\0')
    {
        length = length +1;
    }
}
You can get the length of the string with strlen().

Use the look a check if the character vpassword[i] is an uppercase letter with isupper(), a lowercase letter with islower(), is a digit with isdigit().
http://pubs.opengroup.org/onlinepubs/007908799/xsh/ctype.h.html
thats what i have but it doesnt like my "strlen(6);"


#include <cstdlib>
#include <iostream>
#include <iomanip> //to format output
#include <string>
#include <fstream>
#include <ctype.h>



using namespace std;

int main(int argc, char *argv[])
{
strlen(6);
bool bool6, boollc, booluc, boold;

cout << "Enter your Employee password:";
cin >> vpassword;
bool validate(char* vpassword);
if (vpassword > 6)
for(int i=0; i<20; i++)
{
if (vpassword[i] != '\0')
{
length = length +1;
}
}

int isupper(int c);

int islower(int c);





return 0;
}

bool validate(char* vpassword)
{
int length =0;
bool bool6, boollc, booluc, boold;
if (length > 6)
for(int i=0; i<20; i++)
{
if (vpassword[i] != '\0')
{
length = length +1;
}
}
if (length <6)
{
bool6 = 1;
}
}
it seems to work up to this point but know i need to know how to store the input and check it

#include <cstdlib>
#include <iostream>
#include <iomanip> //to format output
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
int length =0;
char vpassword[6];
char i = 6;
bool bool6, boollc, booluc, boold;

cout << "Enter your Employee password:";
cin >> vpassword;
bool validate(char* vpassword);
if (vpassword[i]>='0' && vpassword[i]<='6')
for(int i=0; i<20; i++)
{
if (vpassword[i] != '\0')
{
length = length +1;
}
}



return 0;
}
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
#include <algorithm>
#include <cctype>
#include <cstring>

bool validate( const char* vpassword )
{
   size_t len = std::strlen( vpassword );

   if ( len < 6 ) return ( false );

   if ( !std::any_of( vpassword, vpassword + len, []( char c ) { return ( std::isdigit( c ) ); } ) )
   {
      return ( false );
   }

   if ( !std::any_of( vpassword, vpassword + len, []( char c ) { return ( std::isupper( c ) ); } ) )
   {
      return ( false );
   }

   if ( !std::any_of( vpassword, vpassword + len, []( char c ) { return ( std::islower( c ) ); } ) )
   {
      return ( false );
   }

   return ( true );
}
Topic archived. No new replies allowed.