Last active
November 17, 2020 01:49
-
-
Save agodin3z/49a234603a03bf184f6037f59cc39985 to your computer and use it in GitHub Desktop.
Simple Login with Cpp - Linux y Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <string> | |
#ifdef WINDOWS | |
#include <windows.h> | |
#else | |
// Assume POSIX | |
#include <termios.h> | |
#include <unistd.h> | |
#endif | |
using namespace std; | |
//hidden passwd | |
string hiddenPasswd(){ | |
string psw; | |
cin.ignore(100, '\n'); | |
#ifdef WINDOWS | |
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); | |
DWORD mode = 0; | |
GetConsoleMode(hStdin, &mode); | |
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT)); | |
#else | |
// Assume POSIX | |
termios oldt; | |
tcgetattr(STDIN_FILENO, &oldt); | |
termios newt = oldt; | |
newt.c_lflag &= ~ECHO; | |
tcsetattr(STDIN_FILENO, TCSANOW, &newt); | |
#endif | |
getline(cin, psw); | |
return psw; | |
}//end hidden passwd | |
//main | |
int main() { | |
string username, password; | |
cout << "Ingresa el nombre de usuario: "; | |
cin >> username; | |
cout << "Ingresa su contraseña: "; | |
password = hiddenPasswd(); | |
if (password == "12345") { | |
cout << "\nTu passwd: " << password << endl; | |
} else { | |
cout << "\nError! escribio: " << password << endl; | |
} | |
return 0; | |
}// end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment