stock OnPlayerPasswordStrength(password[]) { new score, strength[12]; new alphabet[][] = { {"a"}, {"b"}, {"c"}, {"d"}, {"e"}, {"f"}, {"g"}, {"h"}, {"i"}, {"j"}, {"k"}, {"l"}, {"m"}, {"n"}, {"o"}, {"p"}, {"q"}, {"r"}, {"s"}, {"t"}, {"u"}, {"v"}, {"w"}, {"x"}, {"y"}, {"z"} }; new numbers[][] = { {"0"}, {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"} }; new symbols[][] = { {"-"}, {"="}, {"_"}, {"+"}, {"!"}, {"@"}, {"#"}, {"$"}, {"%"}, {"^"}, {"&"}, {"*"}, {"("}, {")"}, {"{"}, {"}"}, {"["}, {"]"}, {":"}, {";"}, {"'"}, {"<"}, {">"}, {","}, {"."}, {"?"}, {"/"}, {"|"} }; for(new i = 0; i < 26; i ++) if(strfind(password, alphabet[i], true) != -1) score ++; for(new i = 0; i < 10; i ++) if(strfind(password, numbers[i], true) != -1) score ++; for(new i = 0; i < 28; i ++) if(strfind(password, symbols[i], true) != -1) score += 2; for(new i = 0; i < strlen(password); i ++) { if(password[i] == alphabet[i][0]) { score --; } if(password[i] == numbers[i][0]) { score --; } } if(score <= 2) strength = "Extremely Weak"; if(score >= 3 && score <= 8) strength = "Very Weak"; if(score >= 9 && score <= 14) strength = "Acceptable"; if(score >= 15 && score <= 20) strength = "Strong"; if(score >= 21) strength = "Very Strong"; return strength; }
#include "passwordchecker.inc"
#define REGISTER 0 public OnPlayerCommandText(playerid, cmdtext[]) { if(!strcmp(cmdtext, "/register", true, 9)) { //check here if this username is registered already, or logged in? ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Register this account by writing down your desired password down below.", "Register", "Exit"); // show register box return 1; } return 0; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == REGISTER) { if(strlen(inputtext) < 5) { ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Your password needs to have a minimum of 5 characters to be registered.", "Register", "Exit"); // show register box return 1; } new strength[12]; strength = OnPlayerPasswordStrength(inputtext); if(!strcmp(strength, "Extremely Weak", true, 9)) { ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Your password has been found to be {FF0000}Extremely Weak{FFFFFF}, please try again.", "Register", "Exit"); // show register box //change the above line if you want too. return 1; } if(!strcmp(strength, "Very Weak", true, 9)) { ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Your password has been found to be {FF0000}Very Weak{FFFFFF}, please try again.", "Register", "Exit"); // show register box //change the above line if you want too. return 1; } if(!strcmp(strength, "Acceptable", true, 10)) { //Do your thing, perhaps accept this 'acceptable' password? return 1; } if(!strcmp(strength, "Strong", true, 6)) { //Do your thing return 1; } if(!strcmp(strength, "Very Strong", true, 11)) { //Do your thing return 1; } } return 0; }
Your function returns a null string if the password strength is 1, 2, 3, 8, 9, 14, 15 and 20.
|