[Spielerei: C++] Passwort-Abfrage
Liste der Anhänge anzeigen (Anzahl: 1)
Im folgenden ein kurzes Programm, dass ich aus Langeweile entworfen habe:
Abfrage eines Passwortes über die GetCh() - Input Funktion
Code:
/*Standard Libraries for Input/Output Streaming*/
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
/*String and File Manipulation Streaming*/
#include <string.h>
#include <stdio.h>
#include <fstream.h>
/*Windows and MFC Streaming*/
#include <windows.h>
/*Prototypes for Functions*/
void clrscr(void);
char ConvertF(int);
int main()
{
int CharCounter; /*The ASCII Value of the current character*/
int Counter = 0; /*The Length of the Password*/
const char CurrentPassword[] = "superman"; /*What do we have here?*/
char CollectedPassword[ 20 ]; /*The Entered Password*/
printf("Please Enter your Password: ");
while(CharCounter != 13) /*Loop unless enter has been pressed*/
{
CharCounter = getch(); /*Get input*/
if (CharCounter != 13) /*If it isn't enter*/
{
CollectedPassword[ Counter ] = (char)CharCounter; /*Assign the ASCII Character*/
} /*Continue...*/
if(CharCounter != 13)
{
clrscr(); /*Clear Screen- Password Protection Illusion*/
printf("Please Enter your Password: ");
for(int StarCounter = 0; StarCounter != (Counter+1); StarCounter++) /*Loop for printing out Stars*/
{
printf("*");
}
Counter++; /*Increment Counter for Array*/
}
}
for(int X = 0;X!=(sizeof(CurrentPassword)-1);X++)
{
if(CollectedPassword[X]!=CurrentPassword[X])
{
goto Break;
}
}
printf("\nPassword Correct\n"); /*Success*/
return 0;
Break:
printf("\nWrong Password\n");
return 0;
}
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
Kann die kompilierte Datei nicht hochladen, hat was gegen .exe :(
Achso, ja. 10 Gummipunkte für den Finder des aktuellen Passwortes :D
Offen für Erweiterungs-/Verbesserungsvorschläge :)
* Edit: Archiv angehängt
** Edit: Danke für den Hinweis CoX ;) - Was meinst du "Lass den Passwort dynamisch eingeben", Snev?
|