[Include] Password Strength Checker
#1

Hello, I was bored today and decided to make my first include for you guys and girls.

I've made Password Strength Checker because I haven't really seen one around the sa-mp forums, and whenever I register in a server, it allows me to have any type of password including 123456 or abcdefgh for example.

Sorry for the identation, the samp forums messed it up like this.

Installation

Open a new text file and put in the code down below, enter a name for it, example: passwordchecker.inc
Код:
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;
}
Press save, make sure you put it in your servers include folder (server/pawno/include)
After that put this on top of your script:
Код:
#include "passwordchecker.inc"
EXAMPLE USAGE:

Here's an example usage of the password strength checker:
Код:
#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;
}
I hope you enjoy this code
Reply
#2

How about if you use Capitals? It's securing the password as well.
Reply
#3

What I consider a strong password; Length > 6 && < 12. If it has lower case/upper case characters. Numbers and or symbols.
Reply
#4

Your function returns a null string if the password strength is 1, 2, 3, 8, 9, 14, 15 and 20.
Reply
#5

Not bad.
Reply
#6

To make it even more simpler you could have used regex.
Reply
#7

Good.
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
This calls abcdefgh an acceptable passwrod.
lol wait ill try.
Reply
#9

Great idea, I plan to use this once it has been perfected.

Nice job.
Reply
#10

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Your function returns a null string if the password strength is 1, 2, 3, 8, 9, 14, 15 and 20.
Quote:
Originally Posted by ******
Посмотреть сообщение
This calls abcdefgh an acceptable passwrod.
Both should be fixed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)