Question

In: Computer Science

C++ Language Create Login Register program without open .txt file simple program also if you can...

C++ Language

Create Login Register program without open .txt file
simple program also if you can hide password input
option menu
1) Login
2) Register
3) exit

Solutions

Expert Solution

/* Following code is for changing the input visibility for windows nd linux*/

// checks if its windows or linux
#ifdef WIN32
// if windows then include windows.h header file
#include <windows.h>
#else
// if not windows then include following for unix type os
#include <termios.h>
#include <unistd.h>
#endif

// changes the visibility,if true then visible 
void ChangeInputVisibility(bool show = true)
{
// if windows    
#ifdef WIN32
    // get console handler
    HANDLE stdinHandler = GetStdHandle(STD_INPUT_HANDLE); 
    // stores echoinput env variable dword
    DWORD currentMode;
    GetConsoleMode(stdinHandler, &currentMode);
    // changes consolemode ECHO to show/hide inputs
    if( !show )
        currentMode &= ~ENABLE_ECHO_INPUT;
    else
        currentMode |= ENABLE_ECHO_INPUT;

    // sets the new stdinHandler mode
    SetConsoleMode(stdinHandler, currentMode);

#else
    // changes tty ECHO to show/hide inputs
    struct termios tty;
    tcgetattr(STDIN_FILENO, &tty);
    if( !show )
        tty.c_lflag &= ~ECHO;
    else
        tty.c_lflag |= ECHO;

    (void) tcsetattr(STDIN_FILENO, TCSANOW, &tty);
#endif
}

/* following is the basic code*/

#include<iostream>
#include<string>
using namespace std;

int main(){
    // stores user's selectio
    int option;

    // holds username , password, current password 
    string userName="",password,loginPassword;

    // repeats untill user seletcs exit
    while(true){

        // show menu
        cout << "\n\noption menu" << endl;
        cout << "1) Login" << endl;
        cout << "2) Register " << endl;
        cout << "3) exit" << endl;
        cout << "select an option: ";

        // gets option
        cin >> option;
        switch(option){
            // for option 1
            case 1:

            // if there is already user registered ask password
            if(userName!=""){
                // asks password
                cout << "Enter password: ";
                // hide inputs
                ChangeInputVisibility(false);
                cin >> loginPassword;

                // show inputs
                ChangeInputVisibility(true);

                // if its correct password,then show username
                if(password==loginPassword){
                    cout << "Logged in as " << userName;
                }else{
                    // else invalid password
                    cout << "Password invalid" << endl;
                }
            }else{
                // if there is no existing user name
                cout << "No account registered" << endl;
            }
            break;
            // if user select option 2
            case 2:
            // ask user name and password
            cout << "Enter username: ";
            cin >> userName;
            cout << "Enter password: ";

            // hide inputs
            ChangeInputVisibility(false);
            cin >> password;

            // show inputs
            ChangeInputVisibility(true);
            break;

            // if user select 3
            case 3:

            // exit the programm
            return 0;
            break;

            // for all other inputs,show invalid option
            default:
            cout << "Invalid input!" << endl;
        }
    }
    return 0;
}

Code screenshot:

Output:

PS: If you have any doubts/problems please comment here.Thank You


Related Solutions

Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
Create a C++ login program using file for 2 user. Usernames must be in one file...
Create a C++ login program using file for 2 user. Usernames must be in one file and password in the other file. Ask user for their usernames and password if it matches, they logged in successfully. If it doesn’t match,they have 3 trials ,then they have to sign in and create a username and password. After creating a username and password, they have to go to the login page again. Must work for visual studio code
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Present a screenshot of the following Program to open up the created file in C++ language....
Present a screenshot of the following Program to open up the created file in C++ language. The list of random numbers will be below the instructions I have provided for you a file named Random.txt for use in this program. This file contains a long list of random numbers. You are to write a program that opens the file, reads all the numbers from the file and calculates the following: A. The number of numbers in the file B. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT