954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Password Creator Checker

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.

moiron
Newbie Poster
22 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

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

post some code if you want any more advice.

jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
 

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.

#include <stdio.h>
#include <string.h>

int main (void)
{
	int length;
	char pass[8];
	printf("Enter a password with 8 characters.");
	printf("It must have at least 1 digit and 1 alphabet.");

	fgets( pass, 8, stdin);


that's what i have for now, im trying to add the if function with strlen in it

moiron
Newbie Poster
22 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Use the length() function and return a boolean

string str ("pasword");

if str.length() < 7 {
return 0;
}
else{
return 1:
}

extofer
Posting Whiz in Training
239 posts since Aug 2005
Reputation Points: 8
Solved Threads: 6
 

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

and this is C, not C++

jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
 

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.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
#include<stdio.h>
#include<string.h>

int main()
{
char un[7],pwd[10];
int i,f;
printf("\nEnter user name and pwd");
scanf("%s%s",un,pwd);
if(strlen(un)==7)
{
for(i=0;i<strlen(pwd);i++)
{
if(!isalnum(pwd[i]))
f=1;
}
}
if(f==1)
printf("pwd error");
else
-------proceed---------------
}


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

SNIP

dmachop
Newbie Poster
19 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You