Hello,
I need to write a program that can firstly create user account and store the information ( ID & Password ) and secondly, compares the login data which the user input with pre-stored data.
And i seems to have problem in comparing the login data.
The [b]underline[/b] part doesn't seem to be working as i keyed in the correct input but it doesn't go into the ' if ' statement.
#include<stdio.h>
void main()
{
char username[100][31], password[100][31],usercheck[31],passcheck[31];
int count=0, index=0;
int option;
char Y='y';
int N;
printf("======Password auto-generation and validation ====== \n");
do
{
printf("1)Create the user account< username+password> \n");
printf("2)Validation of login ID and password \n");
printf("3)Password auto-generation. \n");
printf("4)Exit \n");
printf("============================================================ \n");
printf("Enter your option: \n");
flushall();
scanf("%d" , &option);
if(option==1)
{
printf("Please type in user ID: \n");
flushall();
gets(username[index]);
printf("Please type in your password: \n");
gets(password[index]);
do
{
printf("Do u want to create more user?(Y/N) \n");
scanf("%c" , &Y);
if(Y=='y')
{
index++;
printf("Enter a username for user[%d]: \n",index+1);
flushall();
scanf("%s",username[index]);
printf("Please enter a password: \n");
flushall();
gets(password[index]);
}
}while(Y=='y');
}
if(option==2)
{
count=0;
do
{
index++;
printf("Enter your user name:");
flushall();
gets(usercheck);
do
{
if(username[index]==usercheck)
{
printf("Enter the password\n");
gets(passcheck);
}
else
{
index++;
if(index>100)
printf("Invalid username. Please enter again\n");
}
}while(usercheck!=username[index] && index<=100);
}while(index>100);
if(passcheck==password[index])
{
printf("Password check: Pass\n");
}
else
{
do
{
printf("Password is not VALID, you may try again.");
printf("Enter the password\n");
gets(passcheck);
count++;
}while(count<3 && passcheck!=password[index]);
if(count==3)
printf("You have tried 3 times already, no more attempts are allowed!");
if(passcheck==password[index])
printf("Password check: Pass\n");
}
}
}while(option != 4);
}
You cannot compare C strings with operator==, you'll need to use strcmp.
First you should transform your code into C++ code. This is pure (and incorrect) C code, so this is the wrong site to post on.