Login function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Login function

Hello everyone can someone tell me how to insert a simple login function into my program in C++, I want it to be the first thing to show when the program compiles and then continue with the other parts.

31st May 2020, 3:57 PM
Poema Berisha
Poema Berisha - avatar
2 Answers
+ 1
#include <iostream> using namespace std; int main () { string userName; string userPassword; int loginAttempt = 0; while (loginAttempt < 5) { cout << "Please enter your user name: "; cin >> userName; cout << "Please enter your user password: "; cin >> userPassword; if (userName == "greg" && userPassword == "dunn") { cout << "Welcome Greg!\n"; break; } else if (userName == "patrick" && userPassword == "dunn") { cout << "Welcome Patrick!\n"; break; } else { cout << "Invalid login attempt. Please try again.\n" << '\n'; loginAttempt++; } } if (loginAttempt == 5) { cout << "Too many login attempts! The program will now terminate."; return 0; } cout << "Thank you for logging in.\n"; Return 0; }
31st May 2020, 4:09 PM
Abdulsalam Al-Ashwal
Abdulsalam Al-Ashwal - avatar
0
Poema Berisha Yes I can help you with that, Today I did the sololearn PasswordValidator challenge with C++ which can be used in your login system. This is the challenge problem https://www.sololearn.com/learn/7028/?ref=app Here is my solution https://code.sololearn.com/c2ux5eUkeY7g/?ref=app If you want login system file based I can help you with that.
31st May 2020, 4:10 PM
Robin Singh
Robin Singh - avatar