Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5

    C program to check a password against certain criteria


    This program is supposed to ask the user to input a password and then check and make sure it has the correct number of characters, has no symbols, atleast one of the characters being a alpha and one being a numeric. then the program should tell the user what part of the password they did not enter correct.

    this program has the no symbols function, however I can not figure out how to get length function to work with the program. any input would be appreciated or hints of where I should start..

    the following is the working code with just the symbol function
    .....No errors in this code....

    PHP Code:
    #include <stdio.h>
    #pragma warning(disable:4996)
    #include <string.h>  
    #include <ctype.h>   

    void explanation();  


    int length_check(char[]);
    int no_symbols(char[]);   
    int at_least_one_digit(char[]);
    int at_least_one_letter(char[]);  

    int main()
    {
        
    char password[18];
        
    int b;
        
        do     
        {      
            
    printf("Enter your test password\n");
            
    scanf("%s",password);
            
    no_symbols(password);
            if(
    b==0)
                
    printf("Must consist of only alphabetic characters and digits\n");

        }while(
    b!=1); 
        
    printf("Legal password!\n");

        return 
    0;
    }

    int no_symbols(char p[])
    {   
    int i=0,w=0;
        
        while(
    p[i] != '\0'
        {
            if(
    ispunct(p[i])!=0)/
                   
    w++;
            
            
    i++;
        }

        if(
    w==0)
            return 
    1;
        else
            return 
    0;

        } 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Weak password rules. Why no punctuation characters? Is this a homework assignment?

    I guess you need help with the length_check() function, is that correct? You'll have to post that code for us to help you with it, but I would suggest that you lookup strlen().
    I no longer wish to be associated with this site.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5
    Originally Posted by jwdonahue
    Weak password rules. Why no punctuation characters? Is this a homework assignment?

    I guess you need help with the length_check() function, is that correct? You'll have to post that code for us to help you with it, but I would suggest that you lookup strlen().

    yes, this is a homework assignment.. I looked up the strlen().

    With this do I write a length functions similar to the no_symbols function and then have the results of the length function returned to main?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Originally Posted by kraxup
    With this do I write a length functions similar to the no_symbols function and then have the results of the length function returned to main?
    I suppose you could. Depends on the requirements of your assignment really. If you are required to write your own string length function, then you'll just have to figure out how to iterate over the characters in a string until you hit the terminating nul character. If you are not required to write such a function, then why wrap strlen() inside another function? Just call it where you need to get the length of the string.
    I no longer wish to be associated with this site.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5
    Originally Posted by jwdonahue
    I suppose you could. Depends on the requirements of your assignment really. If you are required to write your own string length function, then you'll just have to figure out how to iterate over the characters in a string until you hit the terminating nul character. If you are not required to write such a function, then why wrap strlen() inside another function? Just call it where you need to get the length of the string.

    the program should ask the user for a password. then the program will check the password for strlen() and I have to make the requirment 8 characters long. so if the user inputs a password 8 characters long that function is satisfied.

    then the program will check and make sure the password has atleast one of the 8 characters is a number.

    then the program will say something like password is legal. if the user did not put in a 8 character password with atleast one alpha adn one digit the program will tell the user what function they did not satisfy.

    the password is not hard coded into the source code.


    example:
    program asks enter a password:

    then uset enters:

    help

    the program will tell the user the password did not have 8 characters, the password did not have at least one digit..


    example2:

    the program asks enter a password

    then the user enters:

    2gethelp

    the program will say legal password..
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Any questions?
    I no longer wish to be associated with this site.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5
    Oh yes I have plenty of questions..I do shift work so I have been either sleeping or working the past few days..


    Here is my new code.. When I compile it it compiles and starts to run. When I enter a password the program shuts down, aborts. Can the no_symbols function and the length_check function look so similar.. And on my while statement can I have it look like that so that it is basically saying if those are both true then the program will print legal password..
    Thanks for the help again. I am not trying to get a free ride; however, as a Non progamming fool this may look like a total mess to you...

    PHP Code:
    #include <stdio.h>
    #pragma warning(disable:4996)
    #include <string.h>  
    #include <ctype.h>   




    int length_check(char[]);
    int no_symbols(char[]);   
    int at_least_one_digit(char[]);
    int at_least_one_letter(char[]);  

    int main()
    {
        
    char password[8];
        
    int c;
        
    int b/* I will try and use this for my length function*/
         
        
    do     
        {       
            
    printf("Enter your test password\n");
            
    scanf("%s",password);
            
    no_symbols(password);
            
    length_check(password);

            if(
    c==0)
                
    printf("Must consist of only alphabetic characters and digits\n");
            if(
    b==0)
                
    printf("Your password must be 6 character long\n");

        }
        
        while(
    c!=1,b!=1); 
        
    printf("Legal password!\n");

        return 
    0;
    }

    int no_symbols(char p[])
    {   
         
    int i=0,w=0;
        
        while(
    p[i] != '\0'
        {
            if(
    ispunct(p[i])!=0)/
                   
    w++;
            
            
    i++; 
        }

        if(
    w==0)
            return 
    1;
        else
            return 
    0;

        }

    int length_check(char p[])
    {
        
    int i=0,w=0;
             while(
    p[i] !='\0')
             {
                 if(
    strlen(p[i])!=0)
                     
    w++;
                 
    i++;
             }
             if(
    w==0)
                 return 
    1;
             else
                 return 
    0;

  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    194
    Rep Power
    71
    You don't need any loops if you are going to use strlen().

    this:
    Code:
    int length_check(char p[])
    {
        int i=0,w=0;
             while(p[i] !='\0')
             {
                 if(strlen(p[i])!=0)
                     w++;
                 i++;
             }
             if(w==0)
                 return 1;
             else
                 return 0;
    }
    Becomes just:
    Code:
    ]int length_check(char p[])
    {
    
       if((strlen(p)) >= MinimumPasswordLength)
         return 1;   //OK, whatever value you want for OK to be
    
       return 0;  //not OK
    
    
    //perhaps an easier way to do it is:
    
      int len;
      len = strlen(p);
      if(len >= MinimumPasswordLength)
        return 1; //OK
      else
        return 0;  //not OK
    
    }
    Try to eliminate the tendency to think that "more code is better" and to use meaningless variable names.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5

    Thanks for the help


    Thank you..

    Would I use something like

    PHP Code:
    #define minimumpasswordlength 6 
    to put the minimum length required hard coded into the program
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Originally Posted by kraxup
    When I enter a password the program shuts down, aborts.
    Does it print "Legal password" before it exits? Do you get a run-time or system error?
    I no longer wish to be associated with this site.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5
    The program does not complete the operation. windows immediately says the program has stopped working and is looking for a solution
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    I no longer wish to be associated with this site.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5
    Originally Posted by jwdonahue
    done
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Do you know how to operate a debugger? Step into your code and see where it is crashing.
    I no longer wish to be associated with this site.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    50
    Rep Power
    5

    crash problems


    Originally Posted by jwdonahue
    Do you know how to operate a debugger? Step into your code and see where it is crashing.


    here is the code again, please look at the highlited section in the code. I wrote exactly what the compiler is telling me when the program crashes




    PHP Code:
    #include <stdio.h> 
    #pragma warning(disable:4996) 
    #include <string.h>   
    #include <ctype.h>    




    int length_check(char[]); 
    int no_symbols(char[]);    
    int at_least_one_digit(char[]); 
    int at_least_one_letter(char[]);   

    int main() 

        
    char password[8]; 
        
    int c
        
    int b/* I will try and use this for my length function*/ 
          
        
    do      
        {        
            
    printf("Enter your test password\n"); 
            
    scanf("%s",password); 
            
    no_symbols(password); 
            
    length_check(password); 

            if(
    c==0
                
    printf("Must consist of only alphabetic characters and digits\n"); 
            if(
    b==0
                
    printf("Your password must be 6 character long\n"); 

        } 
         
        while(
    c!=1,b!=1);  
        
    printf("Legal password!\n"); 

        return 
    0


    int no_symbols(char p[]) 
    {    
         
    int i=0,w=0
         
        while(
    p[i] != '\0')  
        { 
            if(
    ispunct(p[i])!=0
                   
    w++; 
             
            
    i++;  
        } 

        if(
    w==0
            return 
    1
        else 
            return 
    0

        } 

    int length_check(char p[]) 
    char password;
      
    int len;
      
    len strlen(p);
      if
          (
    len >= password
    THe compiler is saying that right here is a run time check failure, I am using the word password with it being initialized..
    PHP Code:
       return 1
       


Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo