Advertisement
Guest User

Untitled

a guest
Dec 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define CLS system("cls")
  5. int main(){
  6. CLS;
  7. typedef struct{
  8. char user[20];
  9. char pass[20];
  10. int code;
  11. }user;
  12. int tot;
  13. user a;
  14. FILE *db;
  15. int ch;
  16. char sp;
  17. db=fopen("data.txt","r");
  18. while(fscanf(db,"%c",&sp)>0){
  19. if(sp=='\n'){
  20. tot++;
  21. }
  22. }
  23. fclose(db);
  24. printf("1) Registrati\n2) Fai il login\nInserisci il numero: ");
  25. scanf("%d",&ch);
  26. if(ch==1){
  27. db=fopen("data.txt","a");
  28. CLS;
  29. printf("Inserisci 1 username: ");
  30. scanf("%s",a.user);
  31. printf("Inserisci 1 password: ");
  32. scanf("%s",a.pass);
  33. printf("Inserisci 1 codice di recupero: ");
  34. scanf("%i",&a.code);
  35. fprintf(db,"\n%s\t%s\t%d",a.user,a.pass,a.code);
  36. fclose(db);
  37. }else if(ch==2){
  38. char user[20],pass[20];
  39. int code;
  40. db=fopen("data.txt","r");
  41. CLS;
  42. printf("Inserisci l'username: ");
  43. scanf("%s",user);
  44. printf("Inserisci la password: ");
  45. scanf("%s",pass);
  46. for(int i=0;i<tot;i++){
  47. fscanf(db,"%s\t%s\t%d\n",a.user,a.pass,&a.code);
  48. if(!strcmp(user,a.user)&&(!strcmp(pass,a.pass))){
  49. printf("LOGIN SUCCES");
  50. exit(-1);
  51. }else{
  52. printf("ERROR");
  53. exit(-1);
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement