- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int GetRobustnessValue(const char* s)
- {
- int len; //Length of the input password
- int Robustness; //Local variable used to store password Robustness
- Robustness = 0;
- len = strlen(s);
- int i;
- int j = len - 1;
- for(i = 0; i < j; i++)
- {
- Robustness += abs((short)s[i%len] - (short)s[(i+1)%len]);
- }
- Robustness += abs(((short)s[len] - (short)s[0])/(len -1));
- return Robustness/len;
- }
- void main(int argc, char *argv)
- {
- int Robustness;
- char c[21];
- short len;
- do{
- printf("/n/n");
- printf("please type in the test password, type /"exit/" to exit/n");
- printf("(max length is 20):");
- scanf("%s", &c); //get the password string
- len = strlen(c); //get the length of the password
- if(len > 20) //length out of the range, so the password
- { //is invalid
- printf("Invalid pasword");
- scanf("%d", &Robustness);
- exit(1);
- }
- if(len < 7) //If the length is less of 6, then the
- { //password is definitely weak
- printf("Week password cos it's length is short of 6");
- }
- strongth = GetRobustnessValue(c); //Get password strongth value
- //note: the array c passed to
- // function GetRobustnessValue
- // will degradated to a pointer
- printf("/n");
- printf("The password Robustness is:%d/n", Robustness);
- if((0 <= Robustness) &&(Robustness <= 5))
- printf("Very weak password!");
- if((5 < Robustness) && (Robustness <= 10))
- printf("The Robustness is still need to be improved!");
- if(Robustness >10)
- printf("It's a Robust enough password");
- }while(strcmp(c, "exit")); //If the user type in "exit", then
- //terminate the tester
- //end of while
- }
2008-1-14 0:05