Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define CLS system("cls")
- int main(){
- CLS;
- typedef struct{
- char user[20];
- char pass[20];
- int code;
- }user;
- int tot;
- user a;
- FILE *db;
- int ch;
- char sp;
- db=fopen("data.txt","r");
- while(fscanf(db,"%c",&sp)>0){
- if(sp=='\n'){
- tot++;
- }
- }
- fclose(db);
- printf("1) Registrati\n2) Fai il login\nInserisci il numero: ");
- scanf("%d",&ch);
- if(ch==1){
- db=fopen("data.txt","a");
- CLS;
- printf("Inserisci 1 username: ");
- scanf("%s",a.user);
- printf("Inserisci 1 password: ");
- scanf("%s",a.pass);
- printf("Inserisci 1 codice di recupero: ");
- scanf("%i",&a.code);
- fprintf(db,"\n%s\t%s\t%d",a.user,a.pass,a.code);
- fclose(db);
- }else if(ch==2){
- char user[20],pass[20];
- int code;
- db=fopen("data.txt","r");
- CLS;
- printf("Inserisci l'username: ");
- scanf("%s",user);
- printf("Inserisci la password: ");
- scanf("%s",pass);
- for(int i=0;i<tot;i++){
- fscanf(db,"%s\t%s\t%d\n",a.user,a.pass,&a.code);
- if(!strcmp(user,a.user)&&(!strcmp(pass,a.pass))){
- printf("LOGIN SUCCES");
- exit(-1);
- }else{
- printf("ERROR");
- exit(-1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement