Sometimes it is essential to create a login window when you are making some kind of software. Think , that you wanted to create a login window in your console application using C++ language. this code will help you to do so, by the following code you can get username and password from the user and if both the user name and password is correct you can enter to the application. if not the access will be denied. study the following code carefully and use it in your project when needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <string> #include <conio.h> using namespace std; int main(){ string UserName; string Password =""; char ch; cout << "Enter User Name: "; cin >> UserName; cout << "Enter Password: "; ch = _getch(); while(ch != 13){//character 13 is enter Password.push_back(ch); cout << '*'; ch = _getch(); } if(UserName == "admin" && Password == "password"){ cout << "\nAccess granted :P\n"; }else{ cout << "\nAccess aborted...\n"; } } |
if you have any questions about this code don't hesitate to ask. use the comment section below. and please like out facebook page and share this article with your friends!

Comments
Post a Comment