#include<stdio.h>
#include<string.h>
char Sys_Pass[]="3699";
char verify_Pass(char *P,char *Q)
{
char ch;
ch=strcmp(P,Q);
printf("String Cmp %s,%s is %c %d\n",P,Q,ch,ch);
if(ch==0)
return 1;
else
return 0;
}
void main()
{
char Pass[10],New[10];
char fp=0,sp=0;
printf("Enter Password : ");
scanf("%s",Pass);
if(fp=verify_Pass(Pass,Sys_Pass))
{
Change: printf("Enter a New Password : ");
scanf("%s",Pass);
printf("Re-Type New Password : ");
scanf("%s",New);
if(sp=verify_Pass(Pass,New))
{
strcpy(Sys_Pass,New);
printf("Password Successfully changed\n");
printf("New Password : %s\n",Sys_Pass);
}
else
printf("Passwords Mismatch\n");
}
else
{
if(strcmp(Pass,"111999")==0);
goto Change;
printf("Wrong Password !!!\n");
}
printf("Fp : %c %d\nSp : %c %d\n",fp,fp,sp,sp);
}
This code is always executing the if block and provides the password change even though wrong current password is typed I want to know if there is a logical error if any ?
I am working on a 8051 project which i want to establish a secret password change i.e if i forgot a password and i type password as 111999 it should direct me to the password change menu but here it is always directing to change password menu. This was actually embedded C code but I tried to rectify that using C code but produces same output in both the cases.