Slide show

[Zmodel][slideshow]

Login/Registrarion Using C++ (OOPS)

#include <iostream>
#include <string>

#include <fstream>
using namespace std;

class Person
{
    string user;
    string pass;

public:
    void initial()
    {
        int selection;
        string us, pw;
        cout << "1.Regestration" << endl;
        cout << "2.login" << endl;
        cin >> selection;
        if (selection == 1)
        {
            cout << "Select your Username" << endl;
            cin >> user;
            us = user;
            cout << "Select your Password" << endl;
            cin >> pass;
            pw = pass;
            ofstream outUser;
            outUser.open("User.txt");
            outUser << us;
            outUser.close();
            ofstream outPass;
            outPass.open("Pass.txt");
            outPass << pw;
            outPass.close();
        }

        if (selection == 2)
        {
            cout << "Enter your Username" << endl;
            cin >> user;
            cout << "Enter your Password" << endl;
            cin >> pass;
            ifstream inUser;
            inUser.open("User.txt");
            getline(inUser, us);
            inUser.close();
            ifstream inPass;
            inPass.open("Pass.txt");
            getline(inPass, pw);
            inUser.close();

            if (user == us && pass == pw)
            {
                cout << "Login Sucessfully" << endl;
            }
            else
            {
                cout << "No User Found" << endl;
            }
        }
    }
};
int main()
{

    Person J;
    J.initial();
    return 0;
}

#### OUTPUT #####

1.Regestration 2.login 1 Select your Username Raj1212 Select your Password 1212

1.Regestration 2.login 2 Enter your Username Raj1212 Enter your Password 1212 Login Sucessfully

No comments: