This program compiles and runs, but for some reason xor isn't working....it doesn't save the variable in it's xor'ed form....so for some reason it's having no effect. In execution of the program I've put spots where it spits out the password it read in, i run xor on it before that so it will come out how it should have went to the file.....this is really making me mad. Thanks everyone.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <process.h>
int i=0;
int choice=3;
int didBack=1;
int goAhead=1;
int hackTry=0;
char password[]="4gn890ng08sdhv089vh2390trh820h";
char pword[51];
char newPword[51];
char Key[51];
FILE * passFile;
int main()
{
system("cls");
printf("Login V1.0\nCreated By Drew Peterson\n\n");
/*DO A CHECK HERE FOR THE PASSWORD FILE, IF IT DOESN'T EXIST, PROMPT FOR THE DEFAULT (FIRST) PASSWORD*/
passFile=fopen("c:\\pass.dat","r");
if(passFile!=NULL)
{
fgets(password,50,passFile);
fclose(passFile);
}
else
{
passFile=NULL;
passFile=fopen("c:\\pass.dat","w+");
if(passFile==NULL)
{
printf("\nFile Error, Press Any Key To Reboot");
getch();
fflush(stdin);
//outportb(0xCF9,4);
//outportb(0xCF9,2);
}
else
{
printf("Enter Desired Password: ");
gets(pword);
fflush(stdin);
/*ENCRYPT*/
for(i=0;i<51;i++)
{
pword[i]=pword[i]^Key[i];
}
fputs(pword,passFile);
fclose(passFile);
/*DECRYPT*/
for(i=0;i<51;i++)
{
pword[i]=pword[i]^Key[i];
}
printf("\n\nCongratulations, Your Password Is: ");
printf("%s",pword);
printf("\nYour Computer Must Now Reboot, Press Any Key");
getch();
fflush(stdin);
//outportb(0xCF9,4);
//outportb(0xCF9,2);
}
}
printf("Press 1 To Log In\nPress 2 To Change Password\n\n");
while(choice>2||choice<1)
{
scanf("%d",&choice);
fflush(stdin);
}
if(choice==1)
{
while(goAhead==1)
{
/*DECRYPT*/
for(i=0;i<51;i++)
{
pword[i]=pword[i]^Key[i];
}
printf("%s",password);
printf("Enter Password: ");
for (i=0;i<50;i++)
{
if(didBack==0)
{
i=i-2;
}
didBack=1;
pword[i]=getch();
if(pword[i]=='\r')
{
pword[i]='\0';
break;
}
if(pword[i]=='\b'&&pword[i]>=0)
{
didBack=0;
printf("\b \b");
}
else
{
printf("*");
}
fflush(stdin);
}
if(strcmp(password,pword)==0)
{
goAhead=0;
}
else
{
printf("\nIncorrect Password\n\n");
hackTry++;
if(hackTry>=5)
{
printf("\nYou Have Entered An Incorrect Password Too Many Times,\nPress Any Key To Reboot");
//outportb(0xCF9,4);
//outportb(0xCF9,2);
}
}
}
printf("\nYou Have Successfully Logged In\nPress Any Key To Continue\n");
getch();
fflush(stdin);
//execl("c:\\com.com",0);
}
else
if(choice==2)
{
/*DECRYPT*/
for(i=0;i<51;i++)
{
pword[i]=pword[i]^Key[i];
}
while(goAhead==1)
{
printf("Enter Current Password: ");
for (i=0;i<50;i++)
{
if(didBack==0)
{
i=i-2;
}
didBack=1;
pword[i]=getch();
if(pword[i]=='\r')
{
pword[i]='\0';
break;
}
if(pword[i]=='\b'&&pword[i]>=0)
{
didBack=0;
printf("\b \b");
}
else
{
printf("*");
}
fflush(stdin);
}
if(strcmp(password,pword)==0)
{
goAhead=0;
}
else
{
printf("\nIncorrect Password\n\n");
hackTry++;
if(hackTry>=5)
{
printf("\nYou Have Entered An Incorrect Password Too Many Times,\nPress Any Key To Reboot");
getch();
//outportb(0xCF9,4);
//outportb(0xCF9,2);
}
}
}
if(goAhead==0)
{
printf("\nEnter New Password: ");
gets(newPword);
fflush(stdin);
/*ENCRYPT*/
for(i=0;i<51;i++)
{
pword[i]=pword[i]^Key[i];
}
passFile=fopen("c:\\pass.dat","w+");
fputs(pword,passFile);
fclose(passFile);
printf("Your Password Has Been Changed, Make Note Of It In A Safe Place\nYour Computer Must Now Reboot, Press Any Key");
getch();
fflush(stdin);
//outportb(0xCF9,4);
//outportb(0xCF9,2);
}
}
/*will only get to this point if it failed*/
printf("Failure To Load Operating System, Press Any Key To Reboot");
getch();
/*code to reboot*/
//outportb(0xCF9,4);
// outportb(0xCF9,2);
exit(0);
}