latest Post

How to create different login in C Program


Program :


#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <process.h>
#include <ctype.h>

int chkLogin(); //Login screen - username= Admin Password=tsm
int change(); //conformation from user
void addUser();
struct User
{
char user_id[4];
char user_name[30];
char user_pin[10];
};

void main()
{
char choice;
int pwdchk=0;
pwdchk=chkLogin();
if(pwdchk==1)
{
while(1)
{
clrscr();
textcolor(WHITE);textbackground(BLUE);
gotoxy(25,6);cprintf("        Admin Module      ");
gotoxy(25,8);cprintf("      Add User Details    ");
textbackground(BLACK);
addUser();
getch();
break;
}
}
else if(pwdchk==2)
{
while(1)
{
clrscr();
textcolor(WHITE);textbackground(BLUE);
gotoxy(25,6);cprintf("        User  Module      ");
textbackground(BLACK);
gotoxy(22,10);cprintf("Welcome to user module...!");
getch();
break;
}
}
}

int chkLogin()// Login screen - username= Admin Password=tsm
{
char us[]={"Admin"};
char ps[]={"tsm"};
char u1[10],*p1;
int count=0;
struct User u;
FILE *fp_user;
int j=0;
long int pos;
int logic=1;
fp_user=fopen("userdb.dat","rb+");

start:
clrscr();
textcolor(WHITE);textbackground(BLUE);
gotoxy(25,8);cprintf("        Login Screen      ");
textbackground(BLACK);
gotoxy(25,10);cprintf("Username : ");gets(u1);
gotoxy(25,12);cprintf("Password : ");p1=getpass(" ");

if(strcmp(us,u1)==0)
{
if(strcmp(ps,p1)==0)
{
return 1;
}
}
else
{
while(fp_user!=NULL)
{
pos=ftell(fp_user);
fread(&u,sizeof(u),1,fp_user);
if(strcmp(u.user_name,u1)==0)
{
if(strcmp(u.user_pin,p1)==0)
   {
     fclose(fp_user);
return 2;
    }
}
else
{
if(feof(fp_user)!=0)
{
gotoxy(35,14);cprintf("Invalid Username/Passowrd...");
getch();
fclose(fp_user);
return 0;
}
}
}
}
fclose(fp_user);
}

int change() //changes conformation from user
{
char ch;
gotoxy(35,23);cprintf("If change press'y'?");
fflush(stdin);
ch=getche();
if(toupper(ch)=='Y')
{
fflush(stdin);
return 1;
}
else
{
fflush(stdin);
return 0;
}
}


void addUser()
{
struct User u;
FILE *fp_user;
int wrong=0;
fp_user=fopen("userdb.dat","ab+");
//clrscr();
gotoxy(25,10);cprintf("User ID      : ");fflush(stdin);gets(u.user_id);
gotoxy(25,12);cprintf("User Name    : ");fflush(stdin);gets(u.user_name);
gotoxy(25,14);cprintf("User PIN : ");fflush(stdin);gets(u.user_pin);

if(wrong)
{
gotoxy(25,23);cprintf("Enter the correct data...");
}
else
{
fwrite(&u,sizeof(u),1,fp_user);
gotoxy(20,18);cprintf("Record successfully added list...");
}
fclose(fp_user);
}



Output :













About Open Learning Creative

Open Learning Creative
Recommended Posts × +

0 comments:

Post a Comment

PHP Registration form using GET, POST Methods with example

Program : HTML Code <html> <head> <title>Student Info</title> </head> <body><center> ...