-
-
Save oca159/e2347ea7d34a700150c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| * C++ - Constraseña mostrando asteriscos | |
| * | |
| * Copyright 2014 Martin Cruz Otiniano | |
| * | |
| * Description: Al teclear por consola en lugar de mostrar los caracteres | |
| * mostrara asteriscos, como en cualquier login de cuentas. | |
| * | |
| * Site: www.marcsdev.com | |
| */ | |
| #include <iostream> | |
| #include <conio.h> | |
| using namespace std; | |
| void leerPasw(char frase[]) | |
| { | |
| int i=0; | |
| cout.flush(); | |
| do | |
| { | |
| frase[i] = (unsigned char)getch(); | |
| if(frase[i]!=8) // no es retroceso | |
| { | |
| cout << '*'; // muestra por pantalla | |
| i++; | |
| } | |
| else if(i>0) // es retroceso y hay caracteres | |
| { | |
| cout << (char)8 << (char)32 << (char)8; | |
| i--; //el caracter a borrar e el backspace | |
| } | |
| cout.flush(); | |
| }while(frase[i-1]!=13); // si presiona ENTER | |
| frase[i-1] = NULL; | |
| cout << endl; | |
| } | |
| int main() | |
| { | |
| char pasw[20]; | |
| cout <<" Ingrese password: "; | |
| leerPasw(pasw); | |
| cout << endl; | |
| cout <<" Mostrando password: "<< pasw << endl << endl; | |
| cout <<" >> Puedes agregar la funcion a tus programas :D! \n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment