Code:
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <ctype.h>
#define errDiff "Your password must contain at least one character of 3 of the 4 types: lower, upper, digit and special charac$
#define MAX_LEN 64
int main(void)
{
int rtn = 0, len = 0;
char uname[MAX_LEN], new[MAX_LEN], old[MAX_LEN], mess[MAX_LEN];
printf("Enter username: ");
fgets(uname, sizeof(uname), stdin);
len = strlen(uname);
if( uname[len-1] == '\n' )
uname[len-1] = 0;
printf("Enter old password: ");
fgets(old, sizeof(old), stdin);
len = strlen(old);
if( old[len-1] == '\n' )
old[len-1] = 0;
printf("Enter new password: ");
fgets(new, sizeof(new), stdin);
len = strlen(new);
if( new[len-1] == '\n' )
new[len-1] = 0;
rtn = pwdrestrict_method(uname,new,old,mess);
printf("rtn = %d, UserName=%s, OldPassword=%s, NewPassword=%s, Message=%s\n", rtn, uname, old, new, mess);
return 0;
}
int pwdrestrict_method (UserName, NewPassword, OldPassword, Message)
char * UserName;
char * NewPassword;
char * OldPassword;
char ** Message;
{
char * localMessage;
int charCnt = 0;
int i = 0;
int lCnt = 0, uCnt = 0, dCnt = 0, pCnt = 0, cTypes = 0;
charCnt = strlen(NewPassword);
for (i=0; i<charCnt; i++) {
if (islower(NewPassword[i]))
lCnt++;
else if (isupper(NewPassword[i]))
uCnt++;
else if (isdigit(NewPassword[i]))
dCnt++;
else if (ispunct(NewPassword[i]))
pCnt++;
}
fprintf(stderr, "NewPassword=%s lCnt=%d uCnt=%d dCnt=%d pCnt=%d charCnt=%d\n",NewPassword,lCnt,uCnt,dCnt,pCnt,charCnt);
cTypes = (lCnt!=0) + (uCnt!=0) + (dCnt!=0) + (pCnt!=0);
fprintf(stderr, "cTypes=%d\n",cTypes);
if (cTypes < 3) {
localMessage = malloc(strlen(errDiff)+1);
strcpy(localMessage, errDiff);
*Message = localMessage;
errno = EPERM;
return 1;
}
Message = NULL;
return 0;
}
When I compile and run this code, I don't get a segfault, but I get blank for the debug output for "Message". Being a Java programmer at heart, I am woefully inept at understanding pointer referencing/dereferencing, so I think my deficit here is what's causing my confustion/misunderstanding.