Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<time.h>
- struct date
- {
- char usr_id[30]; //username confirmation
- int dd;
- int mm;
- int yy;
- }dob;
- struct u_address
- {
- char usr_id[30]; //username confirmation
- char nation[10];
- char city[10];
- char tem_add[10];
- char perm_add[10];
- char ward_zip[10];
- }a;
- struct confidential_info
- {
- char username[30];
- char password[30];
- }usr_pswd;
- struct general_info
- {
- char f_name[30];
- char l_name[30];
- char ph_no[20];
- int age;
- char email[40];
- int pin;
- char password[25];
- char username[30];
- double user_balance;
- }g_info;
- /*
- Functions protoypes are defined here:
- they are 1)account creation
- 2)registration form
- 3)pin and username generator (random)
- 4)account viewing (reading account information)
- */
- /*
- To generate security login/pass for users, a random 4 digit pin is generated for users using rand() and srand
- ,and an account id is provided by the program. The id will have the following structure:
- *User's name*+*random string of length 4*
- and the password will use random generator for number of length 4, which will be stored in a dat or binary
- file.
- */
- //Misc function
- void starline();
- void user_menu(char[]);
- //Account creation
- void account_create();
- int pin_user();
- void account_info();
- int unique_user(char[]);
- void read_account_info(char[]);
- //for logging in
- int loginscreen();
- int login(char [],char []);
- //User activity functions
- void checkbalance(char[]);
- void checkbookrequest(char[]);
- void bankoperatingtime(char[]);
- void transferfund(char[]);
- void branch_ATM_locations(char[]);
- void loan_status(char[]);
- void change_password_pin(char[]);
- //defintions
- /*user menu for main function, this function needs to called repetedly, after user completeltes a certain
- task, it also should have logoff option if possible
- */
- //balance check
- void checkbalance(char username[])
- {
- FILE *fp;
- fp=fopen("User_Database_01.dat","r");
- while(!feof(fp))
- {
- fread(&g_info,sizeof(g_info),1,fp);
- if(strcmp(username,g_info.username)==0)
- {
- printf("\n\tCurrent Balance is %lf.",g_info.user_balance);
- fclose(fp);
- break;
- }
- else
- printf("Couldn't find balance, ERROR!");
- fclose(fp);
- break;
- }
- fclose(fp);
- }
- //Menu function
- void user_menu(char username[])
- {
- FILE *fp;
- fp=fopen("User_Database_01.dat","r");
- int choice;
- char repeat;
- printf("\n\n");
- starline();
- printf("\n\nWelcome To User Menu");
- printf("\n\t1.Check Balance");
- printf("\n\t2.Check Book Request");
- printf("\n\t3.Check Bank's Operating Hours");
- printf("\n\t4.Inquire Branch & ATM locations");
- printf("\n\t5.Check Loan Status");
- printf("\n\t6.Change Password or PIN");
- printf("\n\t7.View Account Info");
- printf("\n\n");
- printf("\n\tPlease choose an option:");
- scanf("%d",&choice);
- do
- {
- switch(choice)
- {
- case 1:
- printf("\n\tPlease Wait");
- checkbalance(username);
- break;
- case 2:
- printf("\n\tPlease Wait");
- break;
- case 3:
- printf("\n\tPlease Wait");
- break;
- case 4:
- printf("\n\tPlease Wait");
- break;
- case 5:
- printf("\n\tPlease Wait");
- break;
- case 6:
- printf("\n\tPlease Wait");
- break;
- case 7:
- printf("\n\nPlease Wait:");
- read_account_info(username);
- default:
- printf("\nPlease choose again.");
- exit(1);
- }
- printf("\nWould you like to access the menu again? (Y/N)");
- scanf("%c",&repeat);
- }
- while(repeat=='y' || repeat=='Y');
- }
- int unique_user(char incoming[])
- {
- FILE *fp;
- fp=fopen("User_Database_01.dat","r");
- while(!feof(fp))
- {
- if(incoming==g_info.username)
- {
- fclose(fp);
- return 1;
- break;
- }
- else
- {
- return 0;
- break;
- }
- }
- }
- void starline() //a multi-purpose seperator
- {
- int i;
- for(i=0;i<40;i++)
- {
- printf("***");
- }
- }
- //Function to create pin number, and the suffix for username
- int pin_user()
- {
- {
- srand(time(NULL));
- //This is a seed for random generator, using the current time.
- int random_pin=0;
- int i,j=0;
- while(j<4)
- {
- i=rand()%9;
- random_pin=random_pin*10+i;
- //This creates a 4-digit pin at the end of the loop
- j++;
- }
- return random_pin;
- //return value is used in the registration function to get the pin to the user.
- }
- }
- //Function to create account
- void account_create()
- {
- FILE *fp;
- FILE *fp1,*fp2,*fp3;
- int suffix_int,i;
- char username[34]; //suffix for a username
- int pin; //pin for 2 step authentication
- printf("\n\t\t\t\t\tWelcome to account creation");
- printf("\n\n");
- starline();
- fp=fopen("User_Database_01.dat","a");
- fflush(stdin);
- printf("\nEnter first name:");
- gets(g_info.f_name);
- fflush(stdin);
- printf("\nEnter your last name:");
- gets(g_info.l_name);
- fflush(stdin);
- printf("\nEnter contact number:");
- gets(g_info.ph_no);
- printf("\nEnter your age:");
- scanf("%d",&g_info.age);
- fflush(stdin);
- printf("\nEnter your email address:");
- gets(g_info.email);
- g_info.user_balance=0.00;
- /*Now the program generates a random number
- to assign the username, and create an account number,and create a 4
- digit pin, which is used to log in along with the password.*/
- printf("\tPlease wait while we generate a pin number.");
- pin=pin_user();
- printf("\a");
- printf("\nYour pin number is %04d",pin);
- printf("\nPlease keep your pin secure, and do not tell it to anyone.");
- g_info.pin=pin;
- fflush(stdin);
- printf("\nPlease create a secure password:");
- gets(g_info.password);
- RETRYING:g_info.pin=pin;
- //creating pin for authentication, with a GOTO marker for retrying.
- //now we create a suffix to generate a username
- suffix_int=pin_user();
- sprintf(username,"%s%04d",g_info.f_name,suffix_int);
- //sprintf combines integer and the string to create a username.
- i=unique_user(username);
- if(i==0)
- {
- printf("\nYour username is:%s",username);
- USR_CONFIRM:printf("\nPlease re-type your username for confirmation:");
- //puts(g_info.username);
- }
- else goto RETRYING;
- fflush(stdin);
- //re-confirmation stores the username in the struct's "username" now
- gets(g_info.username);
- fwrite(&g_info,sizeof(g_info),1,fp);
- //Date of Birth input
- printf("\nEnter date of birth");
- //The format is yy/mm/dd.
- //The output format would be the same.
- fp1=fopen("User_DOB.dat","a");
- //opening file for DOB storage
- printf("\n\tYear:");
- scanf("%d",&dob.yy);
- printf("\n\tMonth:");
- scanf("%d",&dob.mm);
- printf("\n\tDay:");
- scanf("%d",&dob.dd);
- //opening file for User Addresses
- fp3=fopen("User_addresses.dat","a");
- //Input for both temp and permanent address of user
- printf("\nEnter Address");
- fflush(stdin);
- printf("\n\tCountry:");
- gets(a.nation); //"a" is the structure for address. Define inside g_info (general info)
- fflush(stdin);
- printf("\n\tCity:");
- gets(a.city);
- fflush(stdin);
- printf("\n\tEnter temporary address:");
- gets(a.tem_add);
- fflush(stdin);
- printf("\n\tEnter permanent address:");
- gets(a.perm_add);
- fflush(stdin);
- printf("\n\tEnter Ward/Zip code:");
- gets(a.ward_zip);
- printf("\a");
- printf("\a");
- //opening file for Confidential info
- fp2=fopen("Confidental.dat","a");
- //copying password and username to a seperate file for quick access.
- // This string will be used to confirm and display information for all the files.
- // For this purpose, we are now copying it throughout all the three files.
- strcpy(usr_pswd.username,g_info.username);
- strcpy(usr_pswd.password,g_info.password);
- fwrite(&usr_pswd,sizeof(usr_pswd),1,fp2);
- //copying usernames to other files for verification
- strcpy(dob.usr_id,g_info.username);
- strcpy(a.usr_id,g_info.username);
- fwrite(&a,sizeof(a),1,fp3);
- fwrite(&dob,sizeof(dob),1,fp1);
- fclose(fp);
- fclose(fp2);
- fclose(fp1);
- fclose(fp3);
- }
- //The login screen function
- int loginscreen()
- {
- FILE *fp;
- int confirm;
- char user[40],password[40];
- int compare;
- fp=fopen("User_Database_01.dat","r");
- ATTEMPT:printf("\nEnter username:");
- scanf("%s",user);
- printf("\nEnter password:");
- scanf("%s",password);
- confirm=login(user,password);
- if(confirm==1)
- {
- user_menu(user); //calling the menu from login-scree, with username in it.
- }
- else
- printf("\nPlease try again, the credentials are incorrect.");
- goto ATTEMPT;
- }
- //Reading or printing account info
- void read_account_info(char user[])
- {
- printf("\n\n");
- int compare;
- starline();
- printf("\nShowing user info for:");
- puts(user);
- FILE *fp1;
- fp1=fopen("User_Database_01.dat","r");
- while(!feof(fp1))
- {
- fread(&g_info,sizeof(g_info),1,fp1);
- if(strcmp(g_info.username,user))
- {
- printf("\nFirst Name:%s",g_info.f_name);
- printf("\nLast Name:%s",g_info.l_name);
- printf("\nContact Number:%s",g_info.ph_no);
- printf("\nAge:%d",g_info.age);
- printf("\nPIN number:%d",g_info.pin);
- printf("\nUsername:%s",g_info.username);
- printf("\nPassword:%s",g_info.password);
- printf("\nEmail:%s",g_info.email);
- }
- }
- }
- //Login user and password check
- int login(char u[],char p[])
- {
- FILE *fp;
- fp=fopen("Confidental.dat","r");
- while(!feof(fp))
- {
- fread(&usr_pswd,sizeof(usr_pswd),1,fp);
- if(!strcmp(u,usr_pswd.username) && !strcmp(p,usr_pswd.password))
- {
- fclose(fp);
- return 1;
- }
- }
- return 0;
- }
- //main function
- int main()
- {
- loginscreen();
- /* if(confirm==0)
- {
- printf("\a\n\tAccess Approved.");
- //switch case for menu:
- printf("\n\n");
- }
- else
- {
- //Acces denied
- printf("\a\n\tAccess Denied.");
- }
- */
- printf("\n\n");
- starline();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement