#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <windows.h>




int main()
{
 char username1[30];
 char username2[30];
 char username3[30];

 char passWord1[25];
 char passWord2[25];
 char passWord3[25];


 int i = 0;
 int uppercase = 0, lowercase = 0, digits = 0, specail = 0, space = 0, time0 = 1000, time1 = 1500, time2 = 3000, time3 = 4000, time4 = 2000;



printf("\nEnter your USERNAME: (Can be your e-mail address)\n");
gets(username1);

printf("\nType again to confirm you USERNAME!\n");
gets(username2);

if ( !strcmp(username1, username2 )|| strcmp(username1, username2 ) == 0){
    printf("\nYour USERNAME has been confirmed\n");
}else{
  system("cls");
  main();
  return(0);
}


l1:printf("\nEnter your password (5~15 characters; no special characters).\nContain upper and lower case letters, digits and no space: \n");
gets(passWord1);
for(i = 0; i < strlen(passWord1); i++){


if( isalpha(passWord1)){
 if( isupper(passWord1)){
        uppercase++;
    }
 if( islower(passWord1)){
        lowercase++;
    }

}

if ( isdigit(passWord1)){
        digits++;
    }

if ( isspace(passWord1)){
        space++;
    }

if ( ispunct(passWord1)){
        specail++;
    }

}

if( !strcmp(passWord1, username1 )|| strcmp(passWord2, username2 ) == 0){
    system("cls");
    printf("\n\nHey, dude, do not keep USERNAME and PASSWORD the same!\n");
    Sleep(time3);
    system("cls");
    main();
    return(0);
}


if(uppercase == 0 || lowercase == 0 || digits == 0 || strlen(passWord1) <= 6 || strlen(passWord1) >= 16 || space != 0 || specail != 0){
system("cls");
printf("\n\nFollow the instructions!!!\n\n");
Sleep(time1);
system("cls");
printf("USERNAME: %s\n", username1);
goto l1;
return(0);
}

else{
        system("cls");
printf("USERNAME: %s\n", username1);
printf("PASSWORD: ******\n\n", passWord1);
printf(" (Good job, password is strong!!!)\n\n");
printf("Type again to confirm your PASSWORD\n");
}
gets(passWord2);
 if ( !strcmp(passWord1, passWord2 )|| strcmp(passWord1, passWord2 ) == 0){
    system("cls");
    printf("\n\nYour PASSWORD has been confirmed\n\nHAVE A NICE DAY!!!\n");
    Sleep(time1);

    system("cls");

    printf("USERNAME: %s\n", username1);
    printf("PASSWORD: %s\n", passWord1);
}else{
  system("cls");
  printf("USERNAME: %s\n", username1);
  goto l1;
  return(0);

}

 Sleep(time3);
 system("cls");

l2:printf("Log In\n\n");
 Sleep(time0);

 printf("User Name:\n\n");
 gets(username3);
 printf("\nPassWord:\n\n");
 gets(passWord3);

 if( (strcmp(username2, username3 ) == 0) && (strcmp(passWord2, passWord3 ) == 0)){
    printf("\nGood job!!! You log in successfully!!!\n");

 }else if((strcmp(passWord2, passWord3) != 0) && (strcmp(username2, username3) == 0)){
    printf("\nYour PASSWORD was WRONG! Try again\n");
    Sleep(time4);
    system("cls");
    goto l2;
 }else if((strcmp(username2, username3) != 0) && (strcmp(passWord2, passWord3 ) == 0)){
    printf("\nYour USERNAME was WRONG! Try again\n");
    Sleep(time4);
    system("cls");
    goto l2;
 }else{
    printf("\nI am SORRY, you got NOTHING right! Try again\n");
    Sleep(time4);
    system("cls");
    goto l2;

 }

 system("pause");

return(0);
}