Online Bank System: About

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

ONLINE BANK SYSTEM

ABOUT:
This is an online bank account program made using c programming language with the
help of Linked Lists.
In this, we can create multiple bank accounts and we can add or withdraw money
from the accounts by logging to the accounts. We can also reset our passwords and can also
delete our accounts.

REQUIREMENTS:
Knowing functions in c programming language and using any data structure for
storing the data.

WORKING:
Linked lists are used for storing the data in this program.
This program basically has six main functions
- Create Account
- Login to account
- Add money
- Withdraw money
- Reset password
- Delete all accounts

Create account:

User will be asked to enter the name, mobile number. Mobile number will be
validated and then user has to set a password for his account.
The data will be sent to PUSH function which will store the data by assigning
it to nodes created earlier and thus a new account will be created for the user.

Login to Account:

The user has to enter the registered mobile number and password in order to
log in to his account.
The data will then be sent to TRAVERSE function. Mobile number will then
be checked in the data stored. If there is an account registered with the number, then
the password be validated and then user will be logged in to the account if the
password matches.

Add Money:

The user should first login to his account in order to add money to his wallet.
Once logged in to his account, user can add money to his wallet and the
updated money will then be stored in the data.

Withdraw Money:

The user should first login to his account in order to withdraw money from his
wallet.
Once logged in to his account, user can withdraw money from his wallet, only
if sufficient balance is present in the user account.

Reset password:

In case, if the user forgot his password, he can reset the password anytime by
entering his registered mobile number and new password.
If there is an account registered with mobile number, the password will be
changed with the new password entered by the user.

Delete account:

When delete account is selected by the user, the POP function will be called
and all the data stored will be deleted.

CODE IMPLEMENTATION:
//RAGHUPATHI M
//1MV18EC052

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>

//functions for managing accounts
void create_account();
void login();
void reset_password();
void delete_accounts();
void add_money();
void withdraw_money();

// stack implemented using singly linked list
typedef struct node
{
    char u_name[20];
    char u_number[12];
    int u_money;
    char u_password[20];
    struct node *next;
}s;
s *top = NULL;

//push data
s *push(s *top, char name[], char number[], int money, char password[])
{
   
    s *p;
    p=(s *)malloc(sizeof(s));
    if(p==NULL)
    {
        printf("No Memory allocated\n");
    }
    else
    {
        strcpy(p->u_name,name);
        strcpy(p->u_number,number);
        p->u_money = money;
        strcpy(p->u_password,password);
        p->next=top;
        top=p;
        
    }
    return(top);
}

//delete data
s *pop(s *top)
{
   s *p;
   if(top==NULL)
   {
       return(top);
   }
   else
   {
       top->u_name;
       top->u_number;
       top->u_money;
       top->u_password;
       top=top->next;
   }
   return(top);
}

//traverse through the data
char traverse(s *top,char number[],char password[],char money[],char resetpass
word[])
{
    if(top==NULL)
    {
        printf("No ACCOUNTS CREATED\nPLEASE CREATE ACCOUNT\n");
    }
    else
    {
        
        char error[20];
        while(top!=NULL)  //traverse through data
        {
            if(strcmp(top>u_number,number) == 0){  //check if mobile num match
es

                if(resetpassword != "no"){          // for resetting password
                    strcpy(top->u_password,resetpassword);
                    return 's';
                }
                else{

                    if(strcmp(top>u_password,password) == 0){   // check if p
assword matches
                        strcpy(error,"no error");

                        printf("\n***LOGIN SUCCESSFULL***\n\n");
                        printf("\tNAME: %s\n",top->u_name);
                        printf("\tMOBILE: %s\n",top->u_number);
                        printf("\tCURRENT BALANCE: %d\n",top->u_money);
                        printf("\tPASSWORD: %s\n",top->u_password);

                        
                        if(money == "Add"){     //add money
                            MONEYADD:
                            printf("\n***ADD MONEY***");
                            int add = 0;
                            printf("\nEnter the amount to be added: ");
                            scanf("%d",&add);
                            top->u_money += add;
                            printf("***Money added successfully***\n");
                            printf("\tCURRENT BALANCE: %d\n",top->u_money); 

                            printf("\nPress A to add money again or any key t
o quit ");
                            getchar();
                            char ch = toupper(getchar());
                            if(ch == 'A') goto MONEYADD;
                        }
                        else if(money == "Withdraw"){       //withdraw money
                            MONEYSUB:
                            printf("\n***WITHDRAW***");
                            int sub = 0;
                            printf("\nEnter the amount you want to withdraw: 
");
                            scanf("%d",&sub);
                            if(sub > (top>u_money) ) {
printf("INSUFFICIENT BALANCE\n");
}
                            else{
                                top->u_money -= sub;
                                printf("***Money withdraw successfull***\n");
                                printf("\tCURRENT BALANCE: %d\
n",top>u_money); 
                            }

                            printf("\nPress W to Withdraw money again or any 
key to quit ");
                            getchar();
                            char ch = toupper(getchar());
                            if(ch == 'W') goto MONEYSUB;
                        }
                        if(money == "no") getchar();
                        printf("\nPress anykey to return back to main menu\
n");
                        getchar();

                        return 's';
                    }
                    else{
                        strcpy(error,"password");
                    } 
                }     
            }
            else {
                strcpy(error,"mobile");
            }

            top=top->next;
        }
    
        if(strcmp(error,"mobile")==0){     // if mobile dos not match
            printf("\nNo account registered with this number\n");
            printf("please Try again or create an account\n");
            return 'u';
        }
        else if(strcmp(error,"password")==0){   // if password doesnot match
            printf("\nwrong password!!\n");   
            printf("Please try again\n");
            return 'u';
        }
     }
}

//main function
int main(){

    mainhome:
     printf("\n\t\t\t#--DSA PROGRAMMING BANK--#\n");
     printf("\t\t________________________________________");
     printf("\n\n\t\t\t   WELCOME TO THE BANK ");
     printf("\n\t\t________________________________________");
     printf("\n\n\t\t > Press C to Create Account  ");
     printf("\n\t\t > Press L to Login to your account  ");
     printf("\n\t\t > press A to add money to account  ");
     printf("\n\t\t > press W to withdraw money from account  ");
     printf("\n\t\t > Press D to Delete all Accounts  ");
     printf("\n\t\t > press R to Reset your Password  ");
     printf("\n\t\t > press Q to quit             ");
     printf("\n\t\t________________________________________\n\n");

    char choice=toupper(getch());

     if (choice=='C')
     {
       create_account();
       goto mainhome;
     }
     else if (choice=='L')
     {
       login();
       goto mainhome;
     }
     else if (choice=='A')
     {
       add_money();
       goto mainhome;
     }
     else if (choice=='W')
     {
       withdraw_money();
       goto mainhome;
     }
     else if (choice=='D')
     {
       delete_accounts();
        goto mainhome;
     }
     else if (choice=='R')
     {
        reset_password();
        goto mainhome;
     }
     else if (choice=='Q')
     {
        printf("\nThank you for visiting our bank!\nHave a great day!!");
        exit(1);
     }

     return 0;
}

//check mobile number
char valid_mobile(char num[]){
    int i = 0;
    while (num[i] != '\0')  //if contains other than numbers
    {
        if(num[i]>='0' && num[i]<='9'){
            char sys = 'v';
        }
        else{
            return 'd';
        }

        i++;
    }
    
    //length of number
    if(strnlen(num,10) != 10) return 'n';
    else return 'y';
       
}

//check password
char passwordcheck(char str[]){

    int i =0;
    int alp = 0;
    int digit = 0;
    int splch = 0;
    int length = 0;

    while(str[i]!='\0')
    {
        if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
        {
            alp++;
        }
        else if(str[i]>='0' && str[i]<='9')
        {
            digit++;
        }
        else if(str[i] == ' ')
        {
            return 's';
        }
        else
        {
            splch++;
        }

        i++;
    }

    length = alp+digit+splch;

    if(alp >=1 && digit >= 1 && splch >= 1 && length >= 4) return 'v';
    else return 'i';
    
}

//create account
void create_account(){

    char name[20];
    char mobile[12];
    char password[20];
    char checkpassword[20];

    printf("***CREATE ACCOUNT***\n");  

    printf("please enter your name:  ");
    scanf("%s",name);
    getchar();

    number:
    printf("\nEnter your 10 digit Mobile number:  ");
    scanf("%s",mobile);
    char count = valid_mobile(mobile);
    if(count == 'n') {
        printf("*****please enter a 10 digit mobile number****\n");
        goto number;
    }
    else if(count == 'd'){
        printf("*****Mobile number should contain only numbers****\n");
        goto number;
    }   

    printf("\nplease set a password\n");
    printf("************NOTE**************\n");
    printf("The password must be minimun 4 characters length and must consist 
an alphabet, a digit and a special character \n");
    printf("password should not contain spaces\n");
    printf("******************************\n");

    enterpassword:
    printf("password:  ");
    scanf("%s",password);
    char p_check = passwordcheck(password);
    if(p_check == 'i'){
        printf("***The password must be minimun 4 characters length and must c
onsist an alphabet, a digit and a special character***\n");
        goto enterpassword;
    }
    else if(p_check == 's') {
        printf("****password should not contain spaces****");
        goto enterpassword;
    }

    reenterpassword:
    printf("Please re-enter your password:  ");
    scanf("%s",checkpassword);

    if(strcmp(password,checkpassword) == 0){

        top = push(top,name,mobile,50,password);

        printf("\n****Account created succesfully*****\n");
        printf("\nRS.50 added to your wallet as welcome bonus\n");
        printf("\nHave a great Day !!!\n");
    }
    else{
        printf("\n***passwords does not match***\n");
        goto reenterpassword;
    }

//login to account
void login(){

    printf("\n***LOGIN TO ACCOUNT***\n"); 

    char mobile[12];
    char password[20];

    printf("Enter your 10 digit Mobile number:  ");
    scanf("%s",mobile);

    printf("Enter your password:  ");
    scanf("%s",password);

    char result = traverse(top,mobile,password,"no","no");
    if(result == 's'){
        printf("\n***SUCCESSFULLY LOGGED OUT***\n");
    }
}
//reset password
void reset_password(){

    printf("\n***RESET PASSWORD***\n"); 

    char mobile[12];
    char password[20];

    printf("Enter your 10 digit Mobile number:  ");
    scanf("%s",mobile);

     printf("Enter your new password\n");
    printf("************NOTE**************\n");
    printf("The password must be minimun 4 characters length and must consist 
an alphabet, a digit and a special character \n");
    printf("password should not contain spaces\n");
    printf("******************************\n");

    enterpassword:
    printf("password:  ");
    scanf("%s",password);

    char p_check = passwordcheck(password);
    if(p_check == 'i'){
        printf("***The password must be minimun 4 characters length and must c
onsist an alphabet, a digit and a special character***\n");
        goto enterpassword;
    }
    else if(p_check == 's'){
        printf("\n****password should not contain spaces****\n");
        goto enterpassword;
    }

    char result = traverse(top,mobile,"no","Add",password);
    if(result == 's'){
        printf("\n***PASSWORD RESET SUCCESSFUL***\n");
    }
}

//delete all accounts
void delete_accounts(){

    do{
        top = pop(top);
    }while (top != NULL);
    printf("\n***ALL ACCOUNTS DELETED***\n");
     
}
//add money to wallet
void add_money(){
    printf("\n****Please Login to Add money****\n");
    char mobile[12];
    char password[20];

    printf("Enter your 10 digit Mobile number:  ");
    scanf("%s",mobile);

    printf("Enter your password:  ");
    scanf("%s",password);

    char result = traverse(top,mobile,password,"Add","no");
    if(result == 's'){
        printf("\n***SUCCESSFULLY LOGGED OUT***\n");
    }
}

//withdraw money from wallet
void withdraw_money(){
    printf("\n****Please Login to Withdraw money****\n");
    char mobile[12];
    char password[20];

    printf("Enter your 10 digit Mobile number:  ");
    scanf("%s",mobile);

    printf("Enter your password:  ");
    scanf("%s",password);

    char result = traverse(top,mobile,password,"Withdraw","no");
    if(result == 's'){
        printf("\n***SUCCESSFULLY LOGGED OUT***\n");
    }
}

CONCLUSION:
This is a program replicating the online Banking system which stores the details of
user accounts temporarily.
We can include the concept of FILES in this program to store the data permanently.

You might also like