Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<conio.h>
- int option;
- struct data
- {
- char name[50],pass[50];
- }inputdata,odata;
- void login(); //function to login
- void signup(); // function to store data of new user
- void password(); // function to store password with hiding it too
- void logincheck(); //function to check username and pass word entered by the user
- void signupcheck(); // function to check the username so that it wont repeat
- void write(); // function to store user data
- int main()
- {
- printf("1. LOGIN \n 2.SIGNUP \n");
- scanf("%d",&option);
- switch(option)
- {
- case 1: login();
- break;
- case 2: signup();
- break;
- default : printf("\n INCORRECT CHOICE !!!!");
- }
- return 0;
- }
- void login()
- {
- printf("Enter your username :- ");
- scanf("%s",inputdata.name);
- printf("Enter your password :- ");
- password();
- logincheck();
- }
- void signup()
- {
- printf("Enter your username :- ");
- scanf("%s",inputdata.name);
- printf("Enter your password :- ");
- signupcheck();
- }
- void password()
- {
- int i=0,run;
- char temp;
- do
- {
- temp=getch();
- if(temp!='\r'||temp=='\b')
- {
- if(temp=='\b')
- {
- --i;
- //inputdata.pass[i]='\0';
- system("CLS");
- printf("1. LOGIN \n 2.SIGNUP \n %d", option);
- printf("\n Enter your username :- %s ",inputdata.name);
- printf("\n Enter your password :- ");
- for(run=0;run<i;++run)
- printf("*");
- }
- else
- {
- inputdata.pass[i]= temp;
- ++i;
- printf("*");
- }
- }
- else
- {
- //printf("You Pressed Enter %s" ,inputdata.pass);
- break;
- }
- }while(i<=49);
- }
- void signupcheck()
- {
- FILE *check;
- check=fopen("data.txt","r");
- while(!feof(check))
- {
- fread(odata.name,1,sizeof(odata.name),check);
- fread(odata.pass,1,sizeof(odata.pass),check);
- if(strcmp(inputdata.name,odata.name)==0)
- {
- printf("\n THIS USERNAME IS ALREADY IN USE PLEASE CHOOSE ANOTHER USERNAME !!!");
- break;
- }
- else
- password();
- write();
- }
- fclose(check);
- }
- void logincheck() //loginchck function!!!!!!
- {
- FILE *out;
- if((out=fopen("data.txt","r"))==NULL)
- {
- printf("ERROR IN OPENING FILE");
- system("pause");
- }
- while(!feof(out))
- {
- fread(odata.name,1,sizeof(odata.name),out);
- fread(odata.pass,1,sizeof(odata.pass),out);
- if(strcmp(inputdata.name,odata.name)==0)
- {
- if(strcmp(inputdata.pass,odata.pass)==0)
- {
- printf("\n LOGIN SUCCESSFUL !!!");
- break;
- }
- else
- printf("\n LOGIN FAILED !!!");
- break;
- }
- else
- {
- printf("\nINCORRECT USERNAME !!!!");
- break;
- }
- }
- fclose(out);
- }
- void write()
- {
- FILE *in;
- if((in=fopen("data.txt","w"))==NULL)
- {
- printf("ERROR IN OPENING FILE");
- system("pause");
- }
- fwrite(inputdata.name,1,sizeof(inputdata.name),in);
- fwrite(inputdata.pass,1,sizeof(inputdata.pass),in);
- fclose(in);
- }
Add Comment
Please, Sign In to add comment