943,650 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 668
  • C RSS
May 5th, 2009
0

Password Creator Checker

Expand Post »
i need help making a password program. it lets the use input a password and check it if it is following the password rules, which are the following:

must have exactly 7 characters, only alphabets and digits are allowed.

i don't exactly know how to put that in an if else function, but i know i have to use that.

i also don't know if the string.h library is needed but, in our book, the question was from a chapter with strings.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
moiron is offline Offline
22 posts
since Apr 2009
May 5th, 2009
0

Re: Password Creator Checker

use "strlen" and check character ranges. look at your ascii table.

post some code if you want any more advice.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
May 5th, 2009
0

Re: Password Creator Checker

i guess i can use that to check the length, and use the if else to see if the length is exactly 7.
and since the password is supposed to be 7 would i need to make the array size 8 for the \0 part of the string?

since u told me to post a code im gonna try but i know its wrong.
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main (void)
  5. {
  6. int length;
  7. char pass[8];
  8. printf("Enter a password with 8 characters.");
  9. printf("It must have at least 1 digit and 1 alphabet.");
  10.  
  11. fgets( pass, 8, stdin);

that's what i have for now, im trying to add the if function with strlen in it
Last edited by moiron; May 5th, 2009 at 5:38 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
moiron is offline Offline
22 posts
since Apr 2009
May 5th, 2009
-1

Re: Password Creator Checker

Use the length() function and return a boolean

string str ("pasword");

if str.length() < 7 {
return 0;
}
else{
return 1:
}
Last edited by extofer; May 5th, 2009 at 6:07 pm.
Reputation Points: 8
Solved Threads: 6
Posting Whiz in Training
extofer is offline Offline
239 posts
since Aug 2005
May 5th, 2009
0

Re: Password Creator Checker

that doesnt help him if his password is supposed to be EXACTLY seven characters, now does it?

and this is C, not C++
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
May 6th, 2009
0

Re: Password Creator Checker

After reading in the password call functions to test each individual rule. Don't try to test all things in one function, or ghod forbid right after the read.
Moderator
Reputation Points: 3278
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,717 posts
since May 2006
May 8th, 2009
0

Re: Password Creator Checker

  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6. char un[7],pwd[10];
  7. int i,f;
  8. printf("\nEnter user name and pwd");
  9. scanf("%s%s",un,pwd);
  10. if(strlen(un)==7)
  11. {
  12. for(i=0;i<strlen(pwd);i++)
  13. {
  14. if(!isalnum(pwd[i]))
  15. f=1;
  16. }
  17. }
  18. if(f==1)
  19. printf("pwd error");
  20. else
  21. -------proceed---------------
  22. }

I think the question is incomplete and need more details...........

SNIP
Last edited by happygeek; May 12th, 2009 at 7:13 am. Reason: fake sig snipped
Reputation Points: 10
Solved Threads: 1
Newbie Poster
dmachop is offline Offline
19 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Change char to int and store in an array
Next Thread in C Forum Timeline: Hex to Decimal





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC