//************************************** // Name: Login Using a Text File in C // Description:While I'm writing my book on C programming I came across with the idea to include in my book topic on File Handling in C. The idea is to write a program using C as my programming language to store a username and password in a text file and create a login program that will ask the user to give the username and password. The program will search for the username and password that is already stored in our text file. In this example the name of the text file is users.txt. I If the username and password are correct and can be located in the text file the program will allow the user to access the system. But if username or password is incorrect the program will not allow the user to access the system. I hope you will find my work useful. Thank you. I am currently accepting programming work, it projects, school and application development. programming projects, thesis and capstone projects, IT consulting. work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you. My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675. Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com // By: Jake R. Pomperada // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** /* login.c Author: Jake Rodriguez Pomperada,MAED-IT Website: http://www.jakerpomperada.com Emails: jakerpomperada@gmail.com and jakerpomperada@aol.com Location : Bacolod City, Negros Occidental Tool : Dev C++ Version 5.11 Date : January 7, 20193:46 PM Monday */ #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> void get_ID_and_PASS(char fileName[30],char *id,char *pass) { FILE *F = fopen(fileName,"r"); if(F) { int count = 0; while(!feof(F)) { char rawLine[50]; fscanf(F,"%s",rawLine); if(!count++) strcpy(id,rawLine); else strcpy(pass,rawLine); } }else printf("Cannot open this file"); fclose(F); } int main() { char fileName[30] = "users.txt"; char userID[50],userPassW[50]; char strID[50]="\0",strPASSW[50]="\0"; char IDpref[50] = "user_id:\0",PASSWpref[50] = "password:\0"; get_ID_and_PASS(fileName,userID,userPassW); char c; int pos = 0; printf("\n\n"); printf("\tLOGIN SECURITY SYSTEM IN C USING TEXT FILES"); printf("\n\n"); printf("\tEnter User Name : "); scanf("%s",&strID); printf("\n"); printf("\tEnter Your Password : "); do { c = getch(); if( isprint(c) ) { strPASSW[ pos++ ] = c; printf("%c", '*'); } else if( c == 9 && pos ) { strPASSW[pos--] = '\0'; printf("%s", "\b \b"); } } while( c != 13 ); strcpy(strID,strcat(IDpref,strID)); strcpy(strPASSW,strcat(PASSWpref,strPASSW)); if (!strcmp(strID,userID)&&!strcmp(strPASSW,userPassW)) { printf("\n\n"); printf("\tCorrect Username And Password\n"); printf("\n\n\tWelcome to the System\n\n"); } else { printf("\n\n"); printf("\tInvalid Username And Password. Try Again\n\n"); } printf("\n\n"); printf("\tEND OF PROGRAM"); printf("\n\n"); system("pause"); }