-1

Hello I am trying to create a password func with c++ that handles up to 12 characters and that can call three separate bool functions: isUpper, isLower, IsPunctuation.

Any suggestions or templates to start with? I'd like to get this part out of the way and go on with my program. Thank you for all your help.

This is what I have so far:

#include<iostream.h>
#include<conio.h> 
#include<string.h> 

char enterPass(); 
void passFunc(); 

char enterPass() { 
    char numPass[12]; 
    char ch; 
    int i=0; 

    while((ch!='\r')||(ch!='\n')&&(i!=11)) { 
       cin>>ch; cout<<'*'; numPass[i]=ch; i++; 
    } 
    return numPass[12]; 
} 

void passFunc() { 
    char pass[12];

    cout<<"Enter password :- ";
    pass=enterPass(); 
    if(strcmp(pass,"myworld")==0) { 
        cout<<"Correct Password"; getch(); 
    } else { 
       cout<<"Wrong Password"; 
       exit(0); 
    } 
} 

int main() { 
    passFunc(); 
    getch(); 
    return 0; 
}
Tim Post
  • 33,371
  • 15
  • 110
  • 174
  • no this is not from school I am 26 years old, I tried using [code] tags but did not work, like I stated I am trying to make a password function for a program im coding that's going to has semi sensitive information and why is my post at negative 2 rep and there had been nothing but unconstructive comments is this not a coding forum? – user1350623 Apr 23 '12 at 17:30

2 Answers2

0

You might want to start building up on a slight (didactic) modification of your code:

#include <iostream> 
using namespace std;

void enterPass(char* numPass) 
{ 
  char ch; 
  int i=0; 

  while ((ch!=10)&&(i!=13)) // ch=10 is "return"
  { 
    ch=(char)getchar(); //input will not be hidden
    numPass[i++]=ch;
  } 
  numPass[--i]='\0';    //need to form a `string`
}; 


void passFunc() 
{ 
  char pass[13]; 
  cout<<"Enter password :- "; 

  enterPass(pass); 
  if(strcmp(pass,"myworld")==0) 
  { 
    cout<<"Correct Password\n"; 
  } 
  else 
  { 
    cout<<"\n|"<<pass<<"|\n";
    cout<<"Wrong Password\n"; 
    exit(0); 
  } 
};


int main() 
{ 
  passFunc(); 
  return 0; 
}

They are voting down your question, because quite likely there will be lots of code doing similar things. You might want to start with this question, and dig along the "possible duplicate" list.

Community
  • 1
  • 1
P Marecki
  • 1,108
  • 15
  • 19
0
int verify_password()
{
char u_name[10];
char u_pwd[10];
int x=1;
cout<<"\n\n   Enter user name : ";
cin>>u_name;
cout<<"\n\n   Enter Password : ";
for(int i=0;i<=10;++i)
{
u_pwd[i]=getch();
cout<<"*";
if(u_pwd[i]==13)
{
u_pwd[i]='\0';
break;
}
}
x=strcmp(admin.user_name,u_name);
if (x==0)
{
    x=strcmp(admin.password,u_pwd);

}
if(x==0)
      cout<<"correct";
    else 
      cout<<"wrong";
}