Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // snack.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include "stdafx.h"
- /*
- for(int x=0; passwort[x] != '\0'; x++){
- passwort[x] = passwort[x]+3;
- }
- fseek (pFile , 0 , SEEK_END);
- lSize = ftell (pFile); -> lSize ist int
- rewind (pFile);
- if(datei!=NULL){
- while(fgets(string,100,datei)){
- laenge = 0;
- for(int i = 0; i < 4; i++){
- for(zaehler=0; string[laenge]!=';';zaehler++){
- substring[i][zaehler] = string[laenge++];
- }
- substring[i][zaehler]='\0';
- laenge++;
- }
- }
- }
- void einlesen(void){
- FILE *datei;
- char retstr[BUFSIZ];
- char *f1, *f2, *p;
- int max_cnt = 5;
- int i, cnt = 0, laenge1 = 0, laenge2 = 0, falsch;
- char account[255], passwort[255], tmp[256] = { 0x0 };
- //struct users usr[5];
- if ((datei = fopen("passwords.txt", "r")) == NULL)
- {
- printf("ERROR: can not open passwords.txt file:\n");
- exit(1);
- }
- while (fgets(retstr, BUFSIZ, datei) != NULL)
- {
- if ((p = strchr(retstr, ';')) != NULL)
- *p = '\0';
- if (cnt == max_cnt)
- break;
- f1 = strtok(retstr, ";");
- f2 = p+1;
- strcpy(usr[cnt].id, f1);
- strcpy(usr[cnt].pw, f2);
- if(usr[cnt].pw[strlen(usr[cnt].pw)-1] == '\n'){
- usr[cnt].pw[strlen(usr[cnt].pw)-1] = '\0';
- }
- strcpy(usr[cnt].id, strtok(retstr, ";"));
- strcpy(usr[cnt].pw, strtok(NULL, ";"));
- strcpy(usr[cnt].vorname, strtok(NULL, ";"));
- strcpy(usr[cnt].nachname, strtok(NULL, ";"));
- cnt++;
- }
- printf("%s;%s;%s;%s", usr[1].id, usr[1].pw,usr[1].vorname,usr[1].nachname);
- _getch();
- }
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- #include <ctype.h>
- #include <string.h>
- #include <sys/types.h>
- #define ö 148
- #define ß 225
- #define ü 129
- #define ä 132
- #define Ü 154
- #define ZEICHENLAENGE 20
- struct users {
- char id[20];
- char pw[20];
- char vorname[30];
- char nachname[30];
- }usr[20];
- void admin(void);
- void user(void);
- void benutzerdb(void);
- int main(void)
- {
- int auswahl = 1;
- do
- {
- system("cls"); //_clrscr();
- printf("Wo wollen Sie hin?\n[1]Admin-Bereich\n[2]User-Bereich\n[0]Programm beenden\n> ");
- scanf("%i", &auswahl);
- switch (auswahl)
- {
- case 1:
- admin();
- break;
- case 2:
- fflush(stdin);
- user();
- break;
- case 0:
- break;
- default:
- printf("Falsche Eingabe! Neue Eingabe:\n> ");
- scanf("%i", &auswahl);
- break;
- }
- } while (auswahl);
- }
- void admin(void)
- {
- char adminpw[ZEICHENLAENGE], laenge;
- int x = 3;
- system("cls"); //_clrscr();
- printf("\t\tBenutzerverwaltung\n\t\tAdmin-Bereich\n\n\n");
- while (x > 0)
- {
- printf("\nSie haben noch %i Versuche das richtige Admin-Passwort einzugeben:\n> ", x);
- fflush(stdin);
- fgets(adminpw, ZEICHENLAENGE, stdin);
- laenge = strlen(adminpw);
- adminpw[laenge - 1] = '\0';
- x--;
- printf("Passwort %cberpr%cfung\n", Ü, ü);
- if (strcmp(adminpw, "lol") == 0)
- {
- system("cls");//_clrscr();
- printf("PASSWORT AKZEPTIERT!");
- benutzerdb();
- break;
- }
- else
- {
- system("cls");//_clrscr();
- printf("FALSCHES PASSWORT EINGEGEBEN!");
- }
- }
- _getch();
- }
- void benutzerdb(void)
- {
- FILE *datei;
- int lSize, wiederholen, psw_wdh = 0, klein = 0, gross = 0, laenge, sonder = 0;
- char account[255], passwort[255], nachname[255], vorname[255];
- char *buffer;
- size_t ergebnis;
- for (int x = 0; x <= 255; x++)
- {
- account[x] = '\0';
- passwort[x] = '\0';
- }
- //öffnen
- system("cls");//_clrscr();
- datei = fopen("passwords.txt", "a");
- if (datei == NULL)
- {
- fputs("Fehler beim laden der Datei", stderr);
- exit(1);
- }
- fflush(stdin);
- //dateigröße auslesen
- fseek(datei, 0, SEEK_END);
- lSize = ftell(datei);
- rewind(datei);
- // speicher zuweisen um die gesamte Datei in den buffer zu laden
- fread(buffer, 1, lSize, datei);
- buffer = (char *)malloc(sizeof(char) * lSize);
- if (buffer == NULL)
- {
- fputs("Fehler beim Auslesen des Datei-endes!", stderr);
- exit(2);
- }
- //die datei in den buffer laden
- ergebnis = fread(buffer, 1, lSize, datei);
- if (ergebnis != lSize)
- {
- fputs("Fehler beim Kopieren der Dateiinformationen in den Buffer", stderr);
- exit(3);
- }
- do
- {
- printf("\nGeben Sie den Accountnamen ein:\n> ");
- fgets(account, sizeof(account), stdin);
- printf("\nGeben Sie den Vornamen ein:\n> ");
- fgets(vorname, sizeof(vorname), stdin);
- printf("\nGeben Sie den Nachnamen ein:\n> ");
- fgets(nachname, sizeof(nachname), stdin);
- // WritePrivateProfileString("Allgemein","Name",
- // "Schmidt","C:\\Users.ini");
- //fputs(account, datei);
- // fwrite(account, 1, sizeof(account)-2, datei);
- while (!psw_wdh)
- {
- klein = 0;
- gross = 0;
- sonder = 0;
- printf("\n\nInformation zum Passwort:\nDas Passwort muss mindestens ");
- // _textcolor(12);
- printf("6 ");
- // _textcolor(7);
- printf("Zeichen und maximal ");
- // _textcolor(12);
- printf("20 ");
- // _textcolor(7);
- printf("Zeichen lang sein und mussdesweiterem ");
- // _textcolor(12);
- printf("ein ");
- // _textcolor(7);
- printf("Sonderzeichen enthalten.");
- // _textcolor(12);
- printf(" (? ! _ % & $)");
- // _textcolor(7);
- printf("\nGeben Sie das Passwort ein:\n> ");
- fgets(passwort, sizeof(passwort), stdin);
- for (int check = 0; passwort[check] != '\n'; check++)
- {
- if (passwort[check] == '?' || passwort[check] == '!' || passwort[check] == '_' || passwort[check] == '%' || passwort[check] == '&' || passwort[check] == '$')
- sonder += 1;
- /* if (passwort[check] == '?')
- fr += 1;
- if (passwort[check] == '!')
- au += 1;
- if (passwort[check] == '_')
- un += 1;
- if (passwort[check] == '%')
- pr += 1;
- if (passwort[check] == '&')
- und += 1;
- if (passwort[check] == '$')
- dol += 1;
- */
- if (passwort[check] >= 97 && passwort[check] <= 122)
- klein += 1;
- if (passwort[check] >= 65 && passwort[check] <= 90)
- gross += 1;
- }
- laenge = strlen(passwort);
- printf("\nIhr Passwort enthielt %i Gross-, %i Kleinbuchstaben und %i Sonderzeichen!\n", gross, klein, sonder);
- if (laenge >= 6 && laenge <= 20)
- {
- if (klein && gross)
- {
- //if (fr || au || un || pr || und || dol)
- if (sonder)
- {
- printf("\n\nPasswort Akzeptiert!\n\n");
- for (int y = 0; account[y] != '\n'; y++)
- fputc(account[y], datei);
- for (int x = 0; passwort[x] != '\n'; x++)
- fputc(passwort[x], datei);
- for (int u = 0; vorname[u] != '\n'; u++)
- fputc(account[u], datei);
- for (int o = 0; nachname[o] != '\n'; o++)
- fputc(account[o], datei);
- break;
- }
- }
- }
- fputc('\n', datei);
- _getch();
- }
- for (int z = 0; passwort[z] != '\n'; z++)
- {
- fputc(passwort[z], datei);
- }
- //fputs(passwort, datei);
- fputc('\n', datei);
- printf("Wiederholen?");
- scanf("%i", &wiederholen);
- fflush(stdin);
- } while (wiederholen); //fwrite(account, 1, sizeof(account), datei);
- fclose(datei);
- free(buffer);
- }
- void user(void)
- {
- FILE *datei;
- char retstr[BUFSIZ], account[255], passwort[255];
- int i, cnt = 0, laenge1 = 0, laenge2 = 0, falsch;
- if ((datei = fopen("passwords.txt", "r")) == NULL)
- {
- printf("ERROR: can not open passwords.txt file:\n");
- exit(1);
- }
- while (fgets(retstr, BUFSIZ, datei) != NULL)
- {
- strcpy(usr[cnt].id, strtok(retstr, ";"));
- strcpy(usr[cnt].pw, strtok(NULL, ";"));
- strcpy(usr[cnt].vorname, strtok(NULL, ";"));
- strcpy(usr[cnt].nachname, strtok(NULL, ";"));
- cnt++;
- }
- printf("%s;%s;%s;%s", usr[1].id, usr[1].pw,usr[1].vorname,usr[1].nachname);
- fclose(datei);
- _getch();
- do
- {
- system("cls");//_clrscr();
- fflush(stdin);
- printf("\nGeben Sie den Account ein:\n> ");
- fgets(account, sizeof(account), stdin);
- laenge1 = strlen(account);
- account[laenge1 - 1] = '\0';
- printf("\nGeben Sie das Passwort ein:\n> ");
- fgets(passwort, sizeof(passwort), stdin);
- laenge2 = strlen(passwort);
- passwort[laenge2 - 1] = '\0';
- printf("%s%s", account, passwort);
- for (int x = 0; x < cnt; x++)
- {
- if (strcmp(usr[x].id, account) == 0)
- {
- if (strcmp(usr[x].pw, passwort) == 0)
- system("\"tictactoe.exe\"");
- falsch = 1;
- }
- }
- } while (falsch == 0);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement