Back Button
Back to Chapter
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.
Collapse_Icon
Table of Contents

Now based on what we have learnt let us try to create a login page.

The login page should ask the user to enter a username, password, and code if the username and either the password or code are correct to provide access.

Assume

password = admin123

username = admin

code=1234

Solution:

#include using namespace std; int main () { string userName; string userPassword; int code; int loginAttempt = 0; while (loginAttempt < 5)//restricting number of time user enters wrong credentials { cout << "Please enter your user name: "; cin >> userName; cout << "Please enter your user password: "; cin >> userPassword; cout << "enter your code:"; cin >> code; // to check if username and password is correct if (userName == "ADMIN") && (userPassword == "admin123" || code==1234) { cout << "Welcome ADMIN!\n"; break; } else { cout<<"try again!!"<
Output: Please enter your user name: ADMIN Please enter your user password: sakmd enter your code:1234 Welcome ADMIN! Thank you for logging in.