Advertisement
Guest User

Untitled

a guest
May 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. // snack.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. /*
  8. for(int x=0; passwort[x] != '\0'; x++){
  9. passwort[x] = passwort[x]+3;
  10. }
  11.  
  12.  
  13.  
  14.  
  15. fseek (pFile , 0 , SEEK_END);
  16. lSize = ftell (pFile); -> lSize ist int
  17. rewind (pFile);
  18.  
  19.  
  20. if(datei!=NULL){
  21. while(fgets(string,100,datei)){
  22. laenge = 0;
  23. for(int i = 0; i < 4; i++){
  24. for(zaehler=0; string[laenge]!=';';zaehler++){
  25. substring[i][zaehler] = string[laenge++];
  26. }
  27. substring[i][zaehler]='\0';
  28. laenge++;
  29. }
  30. }
  31. }
  32.  
  33.  
  34. void einlesen(void){
  35. FILE *datei;
  36. char retstr[BUFSIZ];
  37. char *f1, *f2, *p;
  38. int max_cnt = 5;
  39. int i, cnt = 0, laenge1 = 0, laenge2 = 0, falsch;
  40. char account[255], passwort[255], tmp[256] = { 0x0 };
  41. //struct users usr[5];
  42.  
  43. if ((datei = fopen("passwords.txt", "r")) == NULL)
  44. {
  45. printf("ERROR: can not open passwords.txt file:\n");
  46. exit(1);
  47. }
  48.  
  49. while (fgets(retstr, BUFSIZ, datei) != NULL)
  50. {
  51. if ((p = strchr(retstr, ';')) != NULL)
  52. *p = '\0';
  53. if (cnt == max_cnt)
  54. break;
  55.  
  56. f1 = strtok(retstr, ";");
  57. f2 = p+1;
  58.  
  59. strcpy(usr[cnt].id, f1);
  60. strcpy(usr[cnt].pw, f2);
  61. if(usr[cnt].pw[strlen(usr[cnt].pw)-1] == '\n'){
  62. usr[cnt].pw[strlen(usr[cnt].pw)-1] = '\0';
  63. }
  64.  
  65. strcpy(usr[cnt].id, strtok(retstr, ";"));
  66. strcpy(usr[cnt].pw, strtok(NULL, ";"));
  67. strcpy(usr[cnt].vorname, strtok(NULL, ";"));
  68. strcpy(usr[cnt].nachname, strtok(NULL, ";"));
  69. cnt++;
  70. }
  71.  
  72.  
  73. printf("%s;%s;%s;%s", usr[1].id, usr[1].pw,usr[1].vorname,usr[1].nachname);
  74.  
  75. _getch();
  76.  
  77. }
  78. */
  79.  
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include <time.h>
  83. #include <conio.h>
  84. #include <ctype.h>
  85. #include <string.h>
  86. #include <sys/types.h>
  87.  
  88. #define ö 148
  89. #define ß 225
  90. #define ü 129
  91. #define ä 132
  92. #define Ü 154
  93. #define ZEICHENLAENGE 20
  94.  
  95. struct users {
  96. char id[20];
  97. char pw[20];
  98. char vorname[30];
  99. char nachname[30];
  100. }usr[20];
  101.  
  102.  
  103. void admin(void);
  104. void user(void);
  105. void benutzerdb(void);
  106.  
  107. int main(void)
  108. {
  109. int auswahl = 1;
  110. do
  111. {
  112. system("cls"); //_clrscr();
  113. printf("Wo wollen Sie hin?\n[1]Admin-Bereich\n[2]User-Bereich\n[0]Programm beenden\n> ");
  114. scanf("%i", &auswahl);
  115. switch (auswahl)
  116. {
  117. case 1:
  118. admin();
  119. break;
  120. case 2:
  121. fflush(stdin);
  122. user();
  123. break;
  124. case 0:
  125. break;
  126. default:
  127. printf("Falsche Eingabe! Neue Eingabe:\n> ");
  128. scanf("%i", &auswahl);
  129. break;
  130. }
  131. } while (auswahl);
  132. }
  133.  
  134. void admin(void)
  135. {
  136. char adminpw[ZEICHENLAENGE], laenge;
  137. int x = 3;
  138. system("cls"); //_clrscr();
  139. printf("\t\tBenutzerverwaltung\n\t\tAdmin-Bereich\n\n\n");
  140. while (x > 0)
  141. {
  142. printf("\nSie haben noch %i Versuche das richtige Admin-Passwort einzugeben:\n> ", x);
  143. fflush(stdin);
  144. fgets(adminpw, ZEICHENLAENGE, stdin);
  145. laenge = strlen(adminpw);
  146. adminpw[laenge - 1] = '\0';
  147. x--;
  148. printf("Passwort %cberpr%cfung\n", Ü, ü);
  149. if (strcmp(adminpw, "lol") == 0)
  150. {
  151. system("cls");//_clrscr();
  152. printf("PASSWORT AKZEPTIERT!");
  153. benutzerdb();
  154. break;
  155.  
  156. }
  157. else
  158. {
  159. system("cls");//_clrscr();
  160. printf("FALSCHES PASSWORT EINGEGEBEN!");
  161. }
  162. }
  163. _getch();
  164. }
  165.  
  166. void benutzerdb(void)
  167. {
  168. FILE *datei;
  169. int lSize, wiederholen, psw_wdh = 0, klein = 0, gross = 0, laenge, sonder = 0;
  170. char account[255], passwort[255], nachname[255], vorname[255];
  171. char *buffer;
  172. size_t ergebnis;
  173. for (int x = 0; x <= 255; x++)
  174. {
  175. account[x] = '\0';
  176. passwort[x] = '\0';
  177. }
  178. //öffnen
  179. system("cls");//_clrscr();
  180. datei = fopen("passwords.txt", "a");
  181. if (datei == NULL)
  182. {
  183. fputs("Fehler beim laden der Datei", stderr);
  184. exit(1);
  185. }
  186. fflush(stdin);
  187. //dateigröße auslesen
  188. fseek(datei, 0, SEEK_END);
  189. lSize = ftell(datei);
  190. rewind(datei);
  191. // speicher zuweisen um die gesamte Datei in den buffer zu laden
  192. fread(buffer, 1, lSize, datei);
  193. buffer = (char *)malloc(sizeof(char) * lSize);
  194. if (buffer == NULL)
  195. {
  196. fputs("Fehler beim Auslesen des Datei-endes!", stderr);
  197. exit(2);
  198. }
  199. //die datei in den buffer laden
  200. ergebnis = fread(buffer, 1, lSize, datei);
  201. if (ergebnis != lSize)
  202. {
  203. fputs("Fehler beim Kopieren der Dateiinformationen in den Buffer", stderr);
  204. exit(3);
  205. }
  206.  
  207. do
  208. {
  209. printf("\nGeben Sie den Accountnamen ein:\n> ");
  210. fgets(account, sizeof(account), stdin);
  211. printf("\nGeben Sie den Vornamen ein:\n> ");
  212. fgets(vorname, sizeof(vorname), stdin);
  213. printf("\nGeben Sie den Nachnamen ein:\n> ");
  214. fgets(nachname, sizeof(nachname), stdin);
  215. // WritePrivateProfileString("Allgemein","Name",
  216. // "Schmidt","C:\\Users.ini");
  217. //fputs(account, datei);
  218. // fwrite(account, 1, sizeof(account)-2, datei);
  219. while (!psw_wdh)
  220. {
  221. klein = 0;
  222. gross = 0;
  223. sonder = 0;
  224. printf("\n\nInformation zum Passwort:\nDas Passwort muss mindestens ");
  225. // _textcolor(12);
  226. printf("6 ");
  227. // _textcolor(7);
  228. printf("Zeichen und maximal ");
  229. // _textcolor(12);
  230. printf("20 ");
  231. // _textcolor(7);
  232. printf("Zeichen lang sein und mussdesweiterem ");
  233. // _textcolor(12);
  234. printf("ein ");
  235. // _textcolor(7);
  236. printf("Sonderzeichen enthalten.");
  237. // _textcolor(12);
  238. printf(" (? ! _ % & $)");
  239. // _textcolor(7);
  240. printf("\nGeben Sie das Passwort ein:\n> ");
  241. fgets(passwort, sizeof(passwort), stdin);
  242. for (int check = 0; passwort[check] != '\n'; check++)
  243. {
  244. if (passwort[check] == '?' || passwort[check] == '!' || passwort[check] == '_' || passwort[check] == '%' || passwort[check] == '&' || passwort[check] == '$')
  245. sonder += 1;
  246. /* if (passwort[check] == '?')
  247. fr += 1;
  248. if (passwort[check] == '!')
  249. au += 1;
  250. if (passwort[check] == '_')
  251. un += 1;
  252. if (passwort[check] == '%')
  253. pr += 1;
  254. if (passwort[check] == '&')
  255. und += 1;
  256. if (passwort[check] == '$')
  257. dol += 1;
  258. */
  259. if (passwort[check] >= 97 && passwort[check] <= 122)
  260. klein += 1;
  261. if (passwort[check] >= 65 && passwort[check] <= 90)
  262. gross += 1;
  263. }
  264. laenge = strlen(passwort);
  265. printf("\nIhr Passwort enthielt %i Gross-, %i Kleinbuchstaben und %i Sonderzeichen!\n", gross, klein, sonder);
  266. if (laenge >= 6 && laenge <= 20)
  267. {
  268. if (klein && gross)
  269. {
  270. //if (fr || au || un || pr || und || dol)
  271. if (sonder)
  272. {
  273. printf("\n\nPasswort Akzeptiert!\n\n");
  274. for (int y = 0; account[y] != '\n'; y++)
  275. fputc(account[y], datei);
  276.  
  277. for (int x = 0; passwort[x] != '\n'; x++)
  278. fputc(passwort[x], datei);
  279. for (int u = 0; vorname[u] != '\n'; u++)
  280. fputc(account[u], datei);
  281. for (int o = 0; nachname[o] != '\n'; o++)
  282. fputc(account[o], datei);
  283.  
  284. break;
  285. }
  286.  
  287. }
  288.  
  289. }
  290.  
  291.  
  292. fputc('\n', datei);
  293. _getch();
  294. }
  295.  
  296.  
  297.  
  298. for (int z = 0; passwort[z] != '\n'; z++)
  299. {
  300. fputc(passwort[z], datei);
  301. }
  302. //fputs(passwort, datei);
  303. fputc('\n', datei);
  304. printf("Wiederholen?");
  305. scanf("%i", &wiederholen);
  306. fflush(stdin);
  307. } while (wiederholen); //fwrite(account, 1, sizeof(account), datei);
  308. fclose(datei);
  309. free(buffer);
  310.  
  311.  
  312. }
  313. void user(void)
  314. {
  315. FILE *datei;
  316. char retstr[BUFSIZ], account[255], passwort[255];
  317. int i, cnt = 0, laenge1 = 0, laenge2 = 0, falsch;
  318.  
  319. if ((datei = fopen("passwords.txt", "r")) == NULL)
  320. {
  321. printf("ERROR: can not open passwords.txt file:\n");
  322. exit(1);
  323. }
  324.  
  325. while (fgets(retstr, BUFSIZ, datei) != NULL)
  326. {
  327. strcpy(usr[cnt].id, strtok(retstr, ";"));
  328. strcpy(usr[cnt].pw, strtok(NULL, ";"));
  329. strcpy(usr[cnt].vorname, strtok(NULL, ";"));
  330. strcpy(usr[cnt].nachname, strtok(NULL, ";"));
  331. cnt++;
  332. }
  333.  
  334.  
  335. printf("%s;%s;%s;%s", usr[1].id, usr[1].pw,usr[1].vorname,usr[1].nachname);
  336. fclose(datei);
  337. _getch();
  338.  
  339. do
  340. {
  341. system("cls");//_clrscr();
  342. fflush(stdin);
  343. printf("\nGeben Sie den Account ein:\n> ");
  344. fgets(account, sizeof(account), stdin);
  345. laenge1 = strlen(account);
  346. account[laenge1 - 1] = '\0';
  347. printf("\nGeben Sie das Passwort ein:\n> ");
  348. fgets(passwort, sizeof(passwort), stdin);
  349. laenge2 = strlen(passwort);
  350. passwort[laenge2 - 1] = '\0';
  351. printf("%s%s", account, passwort);
  352.  
  353. for (int x = 0; x < cnt; x++)
  354. {
  355. if (strcmp(usr[x].id, account) == 0)
  356. {
  357. if (strcmp(usr[x].pw, passwort) == 0)
  358. system("\"tictactoe.exe\"");
  359. falsch = 1;
  360. }
  361. }
  362. } while (falsch == 0);
  363.  
  364.  
  365. _getch();
  366. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement