18.08.2013, 13:35
(
Последний раз редактировалось .Mento; 19.08.2013 в 14:36.
Причина: version 2
)
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
Press save, make sure you put it in your servers include folder (server/pawno/include)
After that put this on top of your script:
EXAMPLE USAGE:
Here's an example usage of the password strength checker:
I hope you enjoy this code
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;
}
After that put this on top of your script:
Код:
#include "passwordchecker.inc"
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;
}


