Search
 
SCRIPT & CODE EXAMPLE
 

CPP

simple program for sign in and sign up in c++

    #include<iostream.h>
    #include<fstream.h>
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>

    void register_user();
    void login_user();
    void main_menu();

    int IsLoggedIn()
    {
        char username[20],password[20],un[20],pw[20];
        cout<<"Enter Username: ";gets(username);
        cout<<"Enter Password: ";gets(password);

        ifstream read(username + ".txt");
        getline(un,read);
        getline(pw,read);

        if(un==username && pw==password)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    void main()
    {
        main_menu();
    }

    void main_menu()
    {
        int choice;
        cout<<"1. Register
2. Login
Your Choice: "; cin>>choice;
        switch(choice)
        {
            case 1: register_user(); break;
            case 2: login_user(); break;
            default: break;
        }
    }

    void register_user()
    {
        char username[20], password1[20],password2[20];
        cout<<"Enter Username: ";gets(username);
        rev1:cout<<"Enter Password: ";gets(password1);
        cout<<"Enter Password again: ";gets(password2);
        while (password1!=password2)
        {
            goto rev1;
        }
        ofstream file;
        file.open(username + ".txt");
        file<<username<<endl<<password1;
        file.close();
    }

    void login_user()
    {
        int chk=IsLoggedIn();
        if(chk==1)
        {
            cout<<"Log in successfull!
";
        }
        else
        {
            cout<<"Log in unsucessfull!
";
        }
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to find second smallest element in an array using single loop 
Cpp :: C++ Initializing a thread with a class/object 
Cpp :: new expression 
Cpp :: input numbers to int c++ 
Cpp :: ejemplo 
Cpp :: whatsup 
Cpp :: how you can add intger value to string in c++ 
Cpp :: what is c++ 
Cpp :: initalising array c++ 
Cpp :: c++ bind port 
Cpp :: jquery datepicker default date not working 
Cpp :: convert c++ to mips 
Cpp :: c++ dynamic array 
Cpp :: properties of loop in c++ and how it works 
Cpp :: private access specifier in c++ program 
Cpp :: c++ program that put a space in between characters 
Cpp :: Increase IQ codechef solution in c++ 
Cpp :: how to block the screen c++ 
Cpp :: how initilaize deffult value to c++ class 
Cpp :: code::block uncomment 
Cpp :: c++ tuple example 
Cpp :: converting a string to lowercase inbuld function in cpp 
Cpp :: Diamond pattren program in C++ 
Cpp :: c++ cout format specifier for correct number of decimal points 
Cpp :: cosnt cast 
Cpp :: find largest number in each row in array c++ using function 
Cpp :: 378. Kth Smallest Element in a Sorted Matrix using binary search 
Cpp :: c++ loop through an array 
Cpp :: C++ How to insert and print array elements? 
Cpp :: random 1 diem tren man hinh bang dev c 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =