Pwn-90's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
7 (0.01 per day)
Joined:
12-November 12
Profile Views:
191
Last Active:
User is offline Dec 04 2012 03:50 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Who Cares
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
Playstation
Your Car:
Ford
Dream Kudos:
0

Latest Visitors

No latest visitors to show

Icon   Pwn-90 has not set their status

Posts I've Made

  1. In Topic: Getting Garbage values for User ID, and how to read profiles off file?

    Posted 4 Dec 2012

    Ok. Can anyone point me in the direction as to why I am getting garbage values for User ID? And I am trying to use a for loop to read each struct off of the file and assign the values to arrays, but I don't know if this makes any sense. I was under the impression that this was the way to do it, unless I pull each struct and assign it a new struct?
  2. In Topic: program does not properly authenticate username/password

    Posted 13 Nov 2012

    AHHHHHH!!!! You guys are awesome! Thanks much for the help! I got it running, finished code is below if you care to run it.

    #include <stdio.h>
    #include <stdlib.h>
    #define BUFFER 256
    struct profile
    {
      char user[10];
      char pass[10];
      char last[15];
      char first[15];
    };
    //prototypes
      void mainmenu(struct profile User [], int size, int *ucount);
      void signup(struct profile User [], int size, int *ucount);
      void signin(struct profile User [], int size, int *ucount);
      void adminSignup(struct profile User [], int size, int *ucount);
      void userSignup(struct profile User [], int size, int *ucount);
      int populate5(struct profile User []);
      int credentials(struct profile User [], int size, int *ucount, char userid[], char pass[]);
    //endprotos
    ////////////////////////////////////////////////////////////////////////////////  
    int main(int argc, char *argv[])
    {
      //declarations
        int size = 15;//create 15 empty profiles
        struct profile User[size];
        int ucount = 0;//used for keeping track of the number of stored accounts
        char choice = ' ';
      
      ucount = populate5(User);//create 5 accounts
      do
      {//beginprog
        system("CLS");
        printf("********** Login Program **********\n");
        printf("1 -- Begin\n");
        printf("2 -- QUIT\n");
        printf("***********************************\n");\
        choice = getch();
        if(choice == '1') mainmenu(User, size, &ucount);
      }while(choice != '2');  
      system("CLS");	
      return 0;
    }//endprog
    ////////////////////////////////////////////////////////////////////////////////
    void mainmenu(struct profile User [], int size, int *ucount)
    {
      //declarations
        char choice = ' ';
        
      do
      {//main menu
        system("CLS");
        printf("********** Main Menu **********\n");
        printf("1 -- Sign Up\n");//create profile
        printf("2 -- Sign In\n");//login
        printf("3 -- Back\n");
        printf("*******************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : signup(User, size, ucount);
                     break;
          case '2' : signin(User, size, ucount);
                     break;
          case '3' : break;
        }
      }while(choice != '3');
    }
    ////////////////////////////////////////////////////////////////////////////////
    void signup(struct profile User [], int size, int *ucount)
    {
      //declarations
        char choice = ' ';
        
      do
      {//main menu
        system("CLS");
        printf("********** Sign Up **********\n");
        printf("1 -- Admin Sign Up\n");//admin creates profiles for users
        printf("2 -- User Sign Up\n");//user creates personal profile
        printf("3 -- Back\n");
        printf("*****************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : adminSignup(User, size, ucount);
                     break;
          case '2' : userSignup(User, size, ucount);
                     break;
          case '3' : break;
        }
      }while(choice != '3');
    }
    ////////////////////////////////////////////////////////////////////////////////
    void adminSignup(struct profile User [], int size, int *ucount)
    {
      //declarations
        int i = 0;
        char userid[BUFFER] = {'\0'};
        char pass[BUFFER] = {'\0'};
        int attempt = 3;//allow 3 tries to login
        char choice = ' ';
        int success = 1;
        int a = 0;
        int len = 0;
        
      do
      {
        system("CLS");
        printf("Enter Admin userID >> ");
        fgets(userid, BUFFER, stdin);//admin username
        len = strlen(userid);
        if(userid[len - 1] == '\n') userid[len-1] = '\0';
        printf("\nEnter Admin password >> ");
        fgets(pass, BUFFER, stdin);//admin password
        len = strlen(pass);
        if(pass[len - 1] == '\n') pass[len-1] = '\0';   
        success = credentials(User, size, ucount, userid, pass);//authenticate
        if(success == 0)
        {//if entries are not correct
          attempt = attempt - 1;
          printf("\nIncorrect entry, you have %d attempts remaining\n",attempt);
          system("PAUSE");
          if(attempt == 0) return;
        } 
      }while(success == 0);
      do
      {//admin authenticated and can create profiles
        system("CLS");
        printf("********** Admin Sign Up **********\n");
        printf("There are %d empty profiles remaining\n", (size - *ucount));     
        printf("1 -- Create New User\n");
        printf("2 -- Back\n");
        printf("***********************************\n");
        choice = getch();
        switch(choice)
        {//enter account information
          case '1' : system("CLS");
                     printf("Enter User First Name >> ");
                     fgets(User[*ucount].first, BUFFER, stdin);
                     len = strlen(User[*ucount].first);
                     if(User[*ucount].first[len - 1] == '\n') User[*ucount].first[len-1] = '\0';    
                     printf("\nEnter User Last Name >> ");
                     fgets(User[*ucount].last, BUFFER, stdin);
                     len = strlen(User[*ucount].last);
                     if(User[*ucount].last[len - 1] == '\n') User[*ucount].last[len-1] = '\0';
                     printf("\nEnter User ID >> ");
                     fgets(User[*ucount].user, BUFFER, stdin);
                     len = strlen(User[*ucount].user);
                     if(User[*ucount].user[len - 1] == '\n') User[*ucount].user[len-1] = '\0';    
                     printf("\nEnter User Password >> ");
                     fgets(User[*ucount].pass, BUFFER, stdin);
                     len = strlen(User[*ucount].pass);
                     if(User[*ucount].pass[len - 1] == '\n') User[*ucount].pass[len-1] = '\0';    
                     *ucount = *ucount + 1;
                     if(*ucount == size)
                     {//if all structures allocated by -size- are filled
                       printf("No more profiles available.");
                       system("PAUSE");
                       system("CLS");
                       return;
                     }
                     break;
          case '2' : break;
        }
      }while(choice != '2');      
    }  
    ////////////////////////////////////////////////////////////////////////////////
    void userSignup(struct profile User [], int size, int *ucount)
    {
      char choice = ' ';
      int len = 0;
      do
      {//user creates personal profile
        system("CLS");
        printf("********** New User Sign Up **********\n");     
        printf("1 -- Create New User\n");
        printf("2 -- Back\n");
        printf("**************************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : system("CLS");
                     printf("Enter User First Name >> ");
                     fgets(User[*ucount].first, BUFFER, stdin);
                     len = strlen(User[*ucount].first);
                     if(User[*ucount].first[len - 1] == '\n') User[*ucount].first[len-1] = '\0';    
                     printf("\nEnter User Last Name >> ");
                     fgets(User[*ucount].last, BUFFER, stdin);
                     len = strlen(User[*ucount].last);
                     if(User[*ucount].last[len - 1] == '\n') User[*ucount].last[len-1] = '\0';
                     printf("\nEnter User ID >> ");
                     fgets(User[*ucount].user, BUFFER, stdin);
                     len = strlen(User[*ucount].user);
                     if(User[*ucount].user[len - 1] == '\n') User[*ucount].user[len-1] = '\0';    
                     printf("\nEnter User Password >> ");
                     fgets(User[*ucount].pass, BUFFER, stdin);
                     len = strlen(User[*ucount].pass);
                     if(User[*ucount].pass[len - 1] == '\n') User[*ucount].pass[len-1] = '\0';
                     *ucount = *ucount + 1;
                     if(*ucount == size)
                     {
                       printf("No more profiles available.");
                       system("PAUSE");
                       system("CLS");
                       return;
                     }
                     break;
          case '2' : break;
        }
      }while(choice != '2');       
    }     
    ////////////////////////////////////////////////////////////////////////////////
    int credentials(struct profile User [], int size, int *ucount, char userid[], char pass[])
    {
      //declarations  
        int i = 0;
        int a = 0;
        int b = 0;
      
      do
      {//checks pointer to array of user input against Stucture arrays
        if(strcmp(userid, User[i].user) == 0) a = 1;//if all characters match, activate flag -a-  
        if(strcmp(pass, User[i].pass) == 0) b = 1;//if all characters match, activate flag -b-   
        if(a == 1 && b ==1) 
        {
          printf("\Login Successful!\n\n");
          system("PAUSE");
          return 1;//if flags -a- and -b- match, validation successful
        }
        else i++;//otherwise move to next account to check againsti++; 
      }while(i<size);
      return 0;
    }
      
    ////////////////////////////////////////////////////////////////////////////////
    void signin(struct profile User [], int size, int *ucount)
    {
      //declarations
        int i = 0;
        char userid[BUFFER] = {0};
        char pass[BUFFER] = {0};
        int attempt = 3;
        int success = 1;
        int len = 0;
     
      do
      {//same as admin login, validate input vs stored
        system("CLS");
        printf("Enter userID >> ");
        fgets(userid, BUFFER, stdin);
        len = strlen(userid);
        if(userid[len - 1] == '\n') userid[len-1] = '\0';
        printf("\nEnter password >> ");
        fgets(pass, BUFFER, stdin);
        len = strlen(pass);
        if(pass[len - 1] == '\n') pass[len-1] = '\0';
        success = credentials(User, size, ucount, userid, pass);
        if(success == 0)
        {
          attempt = attempt - 1;
          printf("\nIncorrect entry, you have %d attempts remaining\n",attempt);
          system("PAUSE");
          if(attempt == 0) return;
        } 
      }while(success == 0);
    }  
    ////////////////////////////////////////////////////////////////////////////////
    int populate5(struct profile User [])
    {//hardcoded accounts, including admin
      strcpy(User[0].first,"John");
      strcpy(User[0].last,"Madden");
      strcpy(User[0].user,"Admin");
      strcpy(User[0].pass,"Pwd");
      
      strcpy(User[1].first,"John");
      strcpy(User[1].last,"Mathews");
      strcpy(User[1].user,"JM561");
      strcpy(User[1].pass,"AAA");
      
      strcpy(User[2].first,"Laura");
      strcpy(User[2].last,"Candy");
      strcpy(User[2].user,"LC968");
      strcpy(User[2].pass,"BBB");
      
      strcpy(User[3].first,"Mark");
      strcpy(User[3].last,"Johnson");
      strcpy(User[3].user,"MJ185");
      strcpy(User[3].pass,"CCC");
      
      strcpy(User[4].first,"Mike");
      strcpy(User[4].last,"Harrison");
      strcpy(User[4].user,"MH115");
      strcpy(User[4].pass,"DDD");
      
      return 5;  
    }     
    
    
  3. In Topic: program does not properly authenticate username/password

    Posted 13 Nov 2012

    Thanks for the replies! Ok, I re-wrote the code as it is below, but now it completely stops working after entering the credentials :/ I changed the code in the credentials function to use strcmp() as well as changed the user input with strlen() to get rid of the '\n' at the end of it.

    #include <stdio.h>
    #include <stdlib.h>
    #define BUFFER 256
    struct profile
    {
      char user[10];
      char pass[10];
      char last[15];
      char first[15];
    };
    //prototypes
      void mainmenu(struct profile User [], int size, int *ucount);
      void signup(struct profile User [], int size, int *ucount);
      void signin(struct profile User [], int size, int *ucount);
      void adminSignup(struct profile User [], int size, int *ucount);
      void userSignup(struct profile User [], int size, int *ucount);
      int populate5(struct profile User []);
      int credentials(struct profile User [], int size, int *ucount, char *USER, char *PASS);
    //endprotos
    ////////////////////////////////////////////////////////////////////////////////  
    int main(int argc, char *argv[])
    {
      //declarations
        int size = 15;//create 15 empty profiles
        struct profile User[size];
        int ucount = 0;//used for keeping track of the number of stored accounts
        char choice = ' ';
      
      ucount = populate5(User);//create 5 accounts
      do
      {//beginprog
        system("CLS");
        printf("********** Login Program **********\n");
        printf("1 -- Begin\n");
        printf("2 -- QUIT\n");
        printf("***********************************\n");\
        choice = getch();
        if(choice == '1') mainmenu(User, size, &ucount);
      }while(choice != '2');  
      system("CLS");	
      return 0;
    }//endprog
    ////////////////////////////////////////////////////////////////////////////////
    void mainmenu(struct profile User [], int size, int *ucount)
    {
      //declarations
        char choice = ' ';
        
      do
      {//main menu
        system("CLS");
        printf("********** Main Menu **********\n");
        printf("1 -- Sign Up\n");//create profile
        printf("2 -- Sign In\n");//login
        printf("3 -- Back\n");
        printf("*******************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : signup(User, size, ucount);
                     break;
          case '2' : signin(User, size, ucount);
                     break;
          case '3' : break;
        }
      }while(choice != '3');
    }
    ////////////////////////////////////////////////////////////////////////////////
    void signup(struct profile User [], int size, int *ucount)
    {
      //declarations
        char choice = ' ';
        
      do
      {//main menu
        system("CLS");
        printf("********** Sign Up **********\n");
        printf("1 -- Admin Sign Up\n");//admin creates profiles for users
        printf("2 -- User Sign Up\n");//user creates personal profile
        printf("3 -- Back\n");
        printf("*****************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : adminSignup(User, size, ucount);
                     break;
          case '2' : userSignup(User, size, ucount);
                     break;
          case '3' : break;
        }
      }while(choice != '3');
    }
    ////////////////////////////////////////////////////////////////////////////////
    void adminSignup(struct profile User [], int size, int *ucount)
    {
      //declarations
        int i = 0;
        char userid[BUFFER] = {'\0'};
        char pass[BUFFER] = {'\0'};
        int attempt = 3;//allow 3 tries to login
        char choice = ' ';
        int success = 0;
        int a = 0;
        int len = 0;
        
      do
      {
        system("CLS");
        printf("Enter Admin userID >> ");
        fgets(userid, BUFFER, stdin);//admin username
        len = strlen(userid);
        if(userid[len - 1] == '\n') userid[len-1] = '\0';
        printf("\nEnter Admin password >> ");
        fgets(pass, BUFFER, stdin);//admin password
        len = strlen(pass);
        if(pass[len - 1] == '\n') pass[len-1] = '\0';   
        char *USER = userid;
        char *PASS = pass;    
        success = credentials(User, size, ucount, USER, PASS);//authenticate
        if(success == 0)
        {//if entries are not correct
          attempt = attempt - 1;
          printf("\nIncorrect entry, you have %d attempts remaining\n",attempt);
          system("PAUSE");
          if(attempt == 0) return;
        } 
      }while(success == 0);
      do
      {//admin authenticated and can create profiles
        system("CLS");
        printf("********** Admin Sign Up **********\n");
        printf("There are %d empty profiles remaining\n", (size - *ucount));     
        printf("1 -- Create New User\n");
        printf("2 -- Back\n");
        printf("***********************************\n");
        choice = getch();
        switch(choice)
        {//enter account information
          case '1' : system("CLS");
                     printf("Enter User First Name >> ");
                     fgets(User[*ucount].first, BUFFER, stdin);
                     len = strlen(User[*ucount].first);
                     if(User[*ucount].first[len - 1] == '\n') User[*ucount].first[len-1] = '\0';    
                     printf("\nEnter User Last Name >> ");
                     fgets(User[*ucount].last, BUFFER, stdin);
                     len = strlen(User[*ucount].last);
                     if(User[*ucount].last[len - 1] == '\n') User[*ucount].last[len-1] = '\0';
                     printf("\nEnter User ID >> ");
                     fgets(User[*ucount].user, BUFFER, stdin);
                     len = strlen(User[*ucount].user);
                     if(User[*ucount].user[len - 1] == '\n') User[*ucount].user[len-1] = '\0';    
                     printf("\nEnter User Password >> ");
                     fgets(User[*ucount].pass, BUFFER, stdin);
                     len = strlen(User[*ucount].pass);
                     if(User[*ucount].pass[len - 1] == '\n') User[*ucount].pass[len-1] = '\0';    
                     *ucount = *ucount + 1;
                     if(*ucount == size)
                     {//if all structures allocated by -size- are filled
                       printf("No more profiles available.");
                       system("PAUSE");
                       system("CLS");
                       return;
                     }
                     break;
          case '2' : break;
        }
      }while(choice != '2');      
    }  
    ////////////////////////////////////////////////////////////////////////////////
    void userSignup(struct profile User [], int size, int *ucount)
    {
      char choice = ' ';
      int len = 0;
      do
      {//user creates personal profile
        system("CLS");
        printf("********** New User Sign Up **********\n");     
        printf("1 -- Create New User\n");
        printf("2 -- Back\n");
        printf("**************************************\n");
        choice = getch();
        switch(choice)
        {
          case '1' : system("CLS");
                     printf("Enter User First Name >> ");
                     fgets(User[*ucount].first, BUFFER, stdin);
                     len = strlen(User[*ucount].first);
                     if(User[*ucount].first[len - 1] == '\n') User[*ucount].first[len-1] = '\0';    
                     printf("\nEnter User Last Name >> ");
                     fgets(User[*ucount].last, BUFFER, stdin);
                     len = strlen(User[*ucount].last);
                     if(User[*ucount].last[len - 1] == '\n') User[*ucount].last[len-1] = '\0';
                     printf("\nEnter User ID >> ");
                     fgets(User[*ucount].user, BUFFER, stdin);
                     len = strlen(User[*ucount].user);
                     if(User[*ucount].user[len - 1] == '\n') User[*ucount].user[len-1] = '\0';    
                     printf("\nEnter User Password >> ");
                     fgets(User[*ucount].pass, BUFFER, stdin);
                     len = strlen(User[*ucount].pass);
                     if(User[*ucount].pass[len - 1] == '\n') User[*ucount].pass[len-1] = '\0';
                     *ucount = *ucount + 1;
                     if(*ucount == size)
                     {
                       printf("No more profiles available.");
                       system("PAUSE");
                       system("CLS");
                       return;
                     }
                     break;
          case '2' : break;
        }
      }while(choice != '2');       
    }     
    ////////////////////////////////////////////////////////////////////////////////
    int credentials(struct profile User [], int size, int *ucount, char *USER, char *PASS)
    {
      //declarations  
        int i = 0;
        int a = 0;
        int b = 0;
      
      do
      {//checks pointer to array of user input against Stucture arrays
        if(strcmp(*USER, User[i].user) == 0)
        {
          a = 1;//if all characters match, activate flag -a-
        }  
        else
        {//otherwise move to next account to check against
          i++;
        } 
      }while(i<size);
      do
      {//same as above, checking validation of input password against stored password
        if(strcmp(*PASS, User[i].pass) == 0)
        {
          b = 1;//if all characters match, activate flag -b-
        }  
        else
        {
          i++;
        }
        if(a == 1 && b ==1) return 1;//if flags -a- and -b- match, validation successful 
      }while(i<size);  
      return 0;
    }
      
    ////////////////////////////////////////////////////////////////////////////////
    void signin(struct profile User [], int size, int *ucount)
    {
      //declarations
        int i = 0;
        char userid[BUFFER] = {0};
        char pass[BUFFER] = {0};
        int attempt = 3;
        int success = 0;
        int len = 0;
     
      do
      {//same as admin login, validate input vs stored
        system("CLS");
        printf("Enter userID >> ");
        fgets(userid, BUFFER, stdin);
        len = strlen(userid);
        if(userid[len - 1] == '\n') userid[len-1] = '\0';
        printf("\nEnter password >> ");
        fgets(pass, BUFFER, stdin);
        len = strlen(pass);
        if(pass[len - 1] == '\n') pass[len-1] = '\0';
        char *USER = userid;
        char *PASS = pass;
        success = credentials(User, size, ucount, USER, PASS);
        if(success == 0)
        {
          attempt = attempt - 1;
          printf("\nIncorrect entry, you have %d attempts remaining\n",attempt);
          system("PAUSE");
          if(attempt == 0) return;
        } 
      }while(success == 0);
      printf("Successful Login!");
      system("PAUSE");
      return;
    }  
    ////////////////////////////////////////////////////////////////////////////////
    int populate5(struct profile User [])
    {//hardcoded accounts, including admin
      strcpy(User[0].first,"John");
      strcpy(User[0].last,"Madden");
      strcpy(User[0].user,"Admin");
      strcpy(User[0].pass,"Pwd");
      
      strcpy(User[1].first,"John");
      strcpy(User[1].last,"Mathews");
      strcpy(User[1].user,"JM561");
      strcpy(User[1].pass,"AAA");
      
      strcpy(User[2].first,"Laura");
      strcpy(User[2].last,"Candy");
      strcpy(User[2].user,"LC968");
      strcpy(User[2].pass,"BBB");
      
      strcpy(User[3].first,"Mark");
      strcpy(User[3].last,"Johnson");
      strcpy(User[3].user,"MJ185");
      strcpy(User[3].pass,"CCC");
      
      strcpy(User[4].first,"Mike");
      strcpy(User[4].last,"Harrison");
      strcpy(User[4].user,"MH115");
      strcpy(User[4].pass,"DDD");
      
      return 5;  
    }     
    
    
  4. In Topic: Intro

    Posted 13 Nov 2012

    Yeah, the COP1000 taught the basic structure of how code looks in IDEs by starting us off with pseudocode. COP2220 is an intro to pure C programming. Honestly, I have no idea what languages to pursue. My dad programs in COBOL for a financial company, and I learned the basics of BASIC about 10 years ago.

My Information

Member Title:
New D.I.C Head
Age:
25 years old
Birthday:
February 13, 1989
Gender:
Location:
Jax, FL
Interests:
Women, Cars, Airsoft, Alcohol, Programming (obviously)
Full Name:
Steve Haren
Years Programming:
0
Programming Languages:
C

Contact Information

E-mail:
Click here to e-mail me

Comments

Pwn-90 has no profile comments yet. Why not say hello?