[C++] Passwort Eingabe
-
Hi,
Ich habe im mom in einem dos fenster eine Passwort aufvorderung:
#include <iostream> #include <cstdlib> #include <string> int main() { std::string buffer; std::string password; password = 'tes'; std::cout << "Please Enter Your Password:" << std::flush; std::cin >> buffer; if (buffer != password) { std::cout << "\nAccess Denied\n" << std::endl; } else { std::cout << "\nCorrect Passwort\n" << std::endl; } system("PAUSE"); return 0; }
Aber ich möchte das Wenn man bei Please Enter you Password, nicht das Passwort im Klartex Sieht, sondern mit Sternchen!
geht sowas? (bzw. gehen Tuts nur Wie )
Danke für Hilfe!
-
Aber ich möchte das Wenn man bei Please Enter you Password, nicht das Passwort im Klartex Sieht, sondern mit Sternchen!
Nicht mit Standard-C++ allein. Unter Verwendung der BS-API ist aber kein Problem. Ich verschiebe dich mal ins Konsolenforum.
-
Danke,
Kann mir jemadn mal meinen Code so modifizeiren das das geht? (Bin blutiger Anfänger)
-
Viperb0y schrieb:
Danke,
Kann mir jemadn mal meinen Code so modifizeiren das das geht? (Bin blutiger Anfänger)
Ja...
#include <conio.h> #include <stdio.h> enum { back_space = 8 }; /* Bei bedarf anpassen... */ char * read_password(char *str, int maxlen) { char *p = str, ch; while (p-str < maxlen-1 && (ch = getch()) != '\r' && ch != '\n') if (ch != back_space) *p++ = ch, putchar('*'); else if (p > str) --p, printf("\b \b"); *p = 0; return str; } int main(void) { char pass[10]; puts(read_password(pass, sizeof pass)); return 0; }
-
Dein sieht gut aus,
Ich habs jetztschon so gemaht:
#include <conio.h> #include <iostream> #include <cstdlib> int main(){ int cp[]={78,101,111}; // Neo int up; _cputs("\nPlease enter the Password:\n"); int i=0; int b=0; int d=0; while(i<3){ i++; _kbhit(); up=getch(); _putch('*'); if(cp[d]!=up){ b++; }; d++; }; if(b==0){ _cputs("\nAccess Granted!\n"); system ("PAUSE"); }; if(b!=0){ _cputs("\nAcces Denined!\nStopping System...!\n"); while(0==0){ _cputs(" \b"); }; }; }
-
while(0==0) ist wohl nicht üblich? while(1) oder while(true) ist wohl weitaus besser.
system("pause") sollte strafrechtlich verfolgt werden -> eine viel bessere Methode findest du in der FAQ unter "Automatisches Schließen verhindern".
_cputs? _putch? Warum nicht cout? Naja hängt wohl mit der conio zusammen.
MfG SideWinder