HX3 Foren

HX3 Foren (https://hx3.de/)
-   Software- und Webentwicklung (https://hx3.de/software-webentwicklung-23/)
-   -   [Spielerei: C++] Passwort-Abfrage (https://hx3.de/software-webentwicklung-23/spielerei-c-passwort-abfrage-11929/)

boonz 20.12.2005 21:39

[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?

Walk 20.12.2005 22:27

AW: [Spielerei: C++] Passwort-Abfrage
 
Kann es sein das das Passwort "superman" ist? :D

Snevsied 21.12.2005 07:50

AW: [Spielerei: C++] Passwort-Abfrage
 
pack das mit winrar oder winzip, und dann kannst du es hochladen!

Verbesserungsvorschlag:
Lass den Paswort dynamisch eingeben, danach binary abspeichern und der andere kann es dann raten, du muss es bei Aufruf des Programms dann einfach aus der Datei auslesen und in einen Array abspeichern.


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:49 Uhr.

Angetrieben durch vBulletin, Entwicklung von Philipp Dörner & Tobias


SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119