⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkpasswd.c

📁 check password
💻 C
📖 第 1 页 / 共 2 页
字号:
   return 0;
}
/*
*Function: checkSymbol
*Usage: int checkSymbolRslt=checkSymbol(password);
*--------------------------------------------------
*Arithmetic or functions: To  check if the password that user input does not have a symbol
*if so then the password is an invalid one
*/
int checkSymbol(char *passWord)
{
   int i=0,checkSymbolRslt=0;
   for(i=0;i<(int)strlen(passWord);i++)
   {
	  int oneSymbolOfPasswd=(int)passWord[i];
      if(isdigit(oneSymbolOfPasswd)||isalpha(oneSymbolOfPasswd))
         ;
      else
      { 
          checkSymbolRslt=1;
          break;
      }
   }
   return checkSymbolRslt;
}
int checkLastNameOrFirstName(char *userName,char *passWord)
{
   int checkName=0;
   //
   //to do checkLastNameOrFirstName here
   //ommited here
   //
   return checkName;
}
/*
*Function: checkPasswdPlusExt
*Usage: int checkPasswdPlusExtRslt=checkPasswdPlusExt(username,password);
*------------------------------------------------------------------------
*Arithmetic or functions: To  check if the password is invalid like this : 
*password=username+extension or
*password=entension+username
*the extension here is a special string eg:'111111','222222','aaaaaaaa' and so on
*/
int checkPasswdPlusExt(char* userName,char* passWord)
{
	int checkPassPlusExt=0;
	int m,n,i,j;
	int mPasswdLen=strlen(passWord);
	int mNameLen=strlen(userName);
	char tempFrontExt[ExtensionLen],tempEndExt[ExtensionLen];
	if(( mPasswdLen > mNameLen ) && ( ( mPasswdLen - mNameLen ) < ExtensionLen))
	{
		for(i=0,j=0;i<mNameLen;i++,j++)
		{
			tempFrontExt[j]=passWord[i];
		}
		tempFrontExt[j]='\0';

		for(i=mPasswdLen - mNameLen,j=0;i<mPasswdLen;i++,j++)
		{
			tempEndExt[j]=passWord[i];
		}
		tempEndExt[j]='\0';
	}
	if( ( mPasswdLen > mNameLen ) && ( ( mPasswdLen - mNameLen ) < ExtensionLen)&&(strcasecmp(userName,tempFrontExt)==0||strcasecmp(userName,tempEndExt)==0))
	{
		//
		//to check the extension string that is after the username
		//
		for( m=0 ; m < (mPasswdLen-mNameLen-1) ; m++)
		{
			if( passWord[m+mNameLen] == passWord[m+mNameLen+1] )                   
				;
			else
			{
                checkPassPlusExt=1;
				break;
			}
		}	
		//
		//to check the extension string that is before the username
		//
		for( n=0; n< (mPasswdLen - mNameLen - 1); n++)
		{
			if( passWord[n] == passWord[n+1])
				;
			else
			{
                checkPassPlusExt=1;
				break;
			}
		}

		if( (m >= ( mPasswdLen - mNameLen - 1 )) || n>= ( mPasswdLen - mNameLen - 1))
		{
			checkPassPlusExt=0;
		}
	}
	else
	{
		checkPassPlusExt=1;
	}
	return checkPassPlusExt;
}
/*
*Function: judgeConfigState
*Usage: int judgeConfigStateRslt=judgeConfigState(configname);
*--------------------------------------------------------------
*Arithmetic or functions: To  judge if configstate exists and if it exists return the sign. 
*/
int judgeConfigState(char *configName)
{
	int configNum ;
	for(configNum = 0;configNum<ConfigCapacity;configNum++)
	{
		if(strcasecmp(configName ,sg_confState[configNum].configName )==0)
		{
			return configNum;
		}
	}
	return configNum;
}
/*
*Function: StringToDigit
*Usage: int aNum=StringToDigit(aChar);
*-------------------------------------
*Arithmetic or functions: To change the first type of the string to digit. 
*/
int StringToDigit(char *str)
{
	int digit = (int)str[0] - 48;
	
	return digit;
	
}
/*
*Function: checkPasswd
*Usage: int checkPasswdRslt=checkPasswd(aChar);
*----------------------------------------------
*Arithmetic or functions: Validate the validation of password!
*we get the config from the struct sg_confState.
*if it is useful,
*then check the password under this condition if it is valid.
*
*/
int checkPasswd(char *userName ,char *passWord)  
{ 
	
	readConfigFile(config);
	readForbidPasswdFile(forbiddenPasswdFile);
	if(judgeConfigState(ConfigState1)!=ConfigCapacity)
	{
		//
		//state ConfigState1 is that password is forbidden in the forbidden library 
		//beacause of its low complexity and low security
		//
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState1)].configState,"y")==0)
		{
			if(checkIfForbidden(passWord)==0)
			{
                 printf("your password is forbidden beacause it's included in the forbidden library!\n"); 
				 return 0;
			}
		}
	}
	if(judgeConfigState(ConfigState2)!=ConfigCapacity)
	{
		//
	    //state ConfigState2 is the minmum len
     	//
		int passwdMinNum = 0;
		passwdMinNum= StringToDigit(sg_confState[judgeConfigState(ConfigState2)].configState);
		if(checkMinLen(passWord,passwdMinNum)==0)
		{ 
     
             printf("your password is too short to get security! The minimum length is %d.\n",passwdMinNum); 
			 return 0;
     
		}
	}
	
	if(judgeConfigState(ConfigState3)!=ConfigCapacity)
	{
		//
	    //state ConfigState3 is username = password
	    //
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState3)].configState,"y")==0)
		{
			if(checkIfSame(userName,passWord)==0)
			{
               printf("Your username can not be same to your password!\n");
			   return 0;
			}
		}
	}
	
	if(judgeConfigState(ConfigState4)!=ConfigCapacity)
	{
		//
		//state ConfigState4 is  all digit or all letters
		//
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState4)].configState,"y")==0)
		{
			if(checkAllDigitsOrAllLetters(passWord)==0)
			{
                 printf("your password can not be all digits nor all letters\n");
				 return 0;
			}
		}
	}
	if(judgeConfigState(ConfigState5)!=ConfigCapacity)
	{
		//
		//state ConfigState5 is that password plus extension
		//
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState5)].configState,"y")==0)
		{
			if(checkPasswdPlusExt(userName,passWord)==0)
			{
				printf("your password should not like this username+'111....' or username+'ssssss....' or '1111...'+username!\n");
				return 0;
			}
		}
	}
	
	if(judgeConfigState(ConfigState6)!=ConfigCapacity)
	{
		//
		//state ConfigState6 is password = username + special string 
		//or  password = special string +username 
		//
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState6)].configState,"y")==0)
		{
			if (checkPasswordAppendix(userName,passWord,speStr)==0)
			{
				printf("your password should not have a appendix before or after your username.the appendix is like this '12345678' or '87654321' or 'abcdefg'.\n");
				return 0;
			}
		}
	}
	
	if(judgeConfigState(ConfigState7)!=ConfigCapacity)
	{
		//
		//state ConfigState7 is  if password has a symbol
		//
		if(strcasecmp(sg_confState[judgeConfigState(ConfigState7)].configState,"y")==0)
		{
			if(checkSymbol(passWord)==0)
			{
                 printf("your password should have special symbols ,eg:@#$^&@\n");
				 return 0;
			}
		}
	}
	return 1;
}
/*
*Function: checkPasswd
*Usage: int checkRslt=checkPasswd( userName, passWord);
*------------------------------------------------------
*This part is the first version that is without the config file
*/
/*int checkPasswd(char* userName,char* passWord)
{
	//
	//the main function to check wether the password is valid or not 
	//
  int c=0;
  if(checkIfForbidden(userName,passWord)==0)
  {
      printf("your password is forbidden beacause it's included in the forbidden library!\n"); 
  }
  else if(checkMinLen(userName,passWord)==0)
  { 
     
     printf("your password is too short to get security!\n"); 
     
  }
  else if(checkIfSame(userName,passWord)==0)
  {
     printf("Your username can not be same to youe password!\n");
  }
  else if(checkAllDigitsOrAllLetters(userName,passWord)==0)
  {
     printf("your password can not be all digits nor all letters\n");
  }
  else if(checkPasswdPlusExt(userName,passWord)==0)
  {
     printf("your password should not like this username+'111....' or username+'ssssss....' or '1111...'+username!\n");

  }
  else if(ReadSpeStringFile(userName,passWord,"PatterbAppendix.txt")==0)
  {
     printf("your password should not have a appendix before or after your username.the appendix is like this '12345678' or '87654321' or 'abcdefg'.\n");

  }
  else if(checkSymbol(userName,passWord)==0)
  {
     printf("your password should have special symbols ,eg:@#$^&@\n");
  }
  else
     c=1;
  return c;
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -