translation/templating
diff --git a/README.md b/README.md
index 0f0e0e0..61a0ffa 100644
--- a/README.md
+++ b/README.md
@@ -99,3 +99,33 @@
 `MAIL_HOST_DIRECT_FALLBACK` variable if set will cause the `FALLBACK_SMTP` to be
 used instead of SMTP if the user is trying to register with an email host that
 is on that list.
+
+### Translating
+
+The `LANG_CC` variable if set will determine different templates to be used by
+default.
+It is reccomended to set to a 2 letter country code like `il`, `pt`, `us`, `uk`
+and so on, but you can use any string. 
+
+To get started templating and translating get started by setting that variable
+to some string like "il" and copy the template folder:
+```
+cp -r templates templates_il
+```
+
+Pay attention to the undescore + `LANG_CC` termination. In that example if
+LANG_CC is set to `il` then templates_il will be loaded by default. Otherwise
+you can access different languages either by passing the termination as a uri
+path or with the lang GET parameter like in `?lang=il`. Let's suppose you
+created a templates_pt folder. So you can either access that version of the
+site with `mysite.com/signup/pt` or `mysite.com/signup?lang=pt`
+
+One important file to edit under templates is strings.php. This file contains
+many strings in a template format that are used in some parts of the
+application, like validation errors on the frontend. Pay attention to the
+template notation with double braces: `{{num}}`.
+
+
+### Field Validation
+
+Check validators.php.
diff --git a/config.php.example b/config.php.example
index 239056f..46c2536 100755
--- a/config.php.example
+++ b/config.php.example
@@ -2,6 +2,9 @@
 // Service base url
 $BASE_URL = "https://example.com/signup";
 
+// Language country code. The default language to look for. Leave empty for the default html folder
+$LANG_CC = "";
+
 // Ldap server
 $HOST = 'localhost';
 $PORT = 389;
diff --git a/index.php b/index.php
index cdc78ec..340a22e 100755
--- a/index.php
+++ b/index.php
@@ -7,6 +7,16 @@
 if (!$DEBUG)    error_reporting(0);
 session_start();
 
+$INCLUDE_STRINGS_PATH = "templates_".$LANG_CC;
+if (isset($LANG_CC) && !empty($LANG_CC)) $TEMPLATE = $INCLUDE_STRINGS_PATH;
+else $TEMPLATE = "templates";
+
+include_once $TEMPLATE.'/strings.php';
+
+if(!file_exists(stream_resolve_include_path($INCLUDE_STRINGS_PATH.'/strings.php'))){
+    echo format($RUNTIME_ERROR->template_not_found, ["template"=>$INCLUDE_STRINGS_PATH, "langcc"=>$LANG_CC]);
+}
+
 
 use Gregwar\Captcha\PhraseBuilder;
 
@@ -14,14 +24,14 @@
 function register_page($error=false){
     include 'config.php';
     if ($error)
-        include 'html/error.htm';
+        include $TEMPLATE.'/error.htm';
     $_SESSION["captcha_token"] = generateRandomString(12);
-    include "html/register.htm";
+    include $TEMPLATE."/register.htm";
     echo '
     <script>
         const reload_captcha = async (e) => {
             var cont = document.getElementById("reload_captcha");
-            cont.innerHTML = "<div class=\'spinner-border text-info\' role=\'status\'><span class=\'sr-only\'>Loading...</span></div>";
+            cont.innerHTML = "<div class=\'spinner-border text-info\' role=\'status\'><span class=\'sr-only\'>'.$STRINGS->reloading_captcha.'</span></div>";
             var img = document.getElementById("captcha")
             var url =  "'.$BASE_URL.'/captcha.php?token='.$_SESSION["captcha_token"].'"
             await fetch(url, { cache: "reload", mode: "no-cors" })
@@ -45,129 +55,17 @@
 
 function verify_request($user){
     unset($_SESSION['captcha_token']);
-    include "config.php";
-    $error = "";
-    if (ldap_user_count($user->user_name)) {
-        $error = $error."This username is already in use! Please choose another username<br>";
-        unset($_POST["username"]);
-    }
-    if (preg_match("/\s/", $user->user_name)) {
-        $error = $error."Username cannot contain whitespaces<br>";
-        unset($_POST["username"]);
-    }
-    if (strlen($user->user_name) > $VAL_USER->max_username) {
-        $error = $error."Username has to be smaller than ".($VAL_USER->max_username+1)." characters<br>";
-        unset($_POST["username"]);
-    }
-    if (strlen($user->user_name) < $VAL_USER->min_username) {
-        $error = $error."Username has to be bigger than ".($VAL_USER->min_username-1)." characters<br>";
-        unset($_POST["username"]);
-    }
-    if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/',$user->user_name)) {
-        $error = $error."The username cannot contain special characters<br>";
-        unset($_POST["username"]);
-    }
-    if (preg_match('/^\d/',$user->user_name)) {
-        $error = $error."The username cannot begin with a number<br>";
-        unset($_POST["username"]);
-    }
-    include "blacklists/usernames.php";
-    if(in_array($user->user_name, $USERNAME_BLACKLIST)) {
-        $error = $error."That Username is not allowed!<br>";
-        unset($_POST["username"]);
-    }
-
-
-    if (preg_match("/\s/", $user->name)) {
-        $error = $error."First Name cannot contain whitespaces<br>";
-        unset($_POST["name"]);
-    }
-    if (strlen($user->name) > $VAL_USER->max_first_name) {
-        $error = $error."First Name has to be smaller than ".($VAL_USER->max_first_name+1)." characters<br>";
-        unset($_POST["name"]);
-    }
-    if (strlen($user->name) < $VAL_USER->min_first_name) {
-        $error = $error."First Name has to be bigger than ".($VAL_USER->min_first_name-1)." characters<br>";
-        unset($_POST["name"]);
-    }
-    if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\0-9]/',$user->name)) {
-        $error = $error."The first name cannot contain special characters or numbers<br>";
-        unset($_POST["name"]);
-    }
-
-
-    if (preg_match("/\s/", $user->last_name)) {
-        $error = $error."Last Name cannot contain whitespaces<br>";
-        unset($_POST["last_name"]);
-    }
-    if (strlen($user->last_name) > $VAL_USER->max_last_name) {
-        $error = $error."Last Name has to be smaller than ".($VAL_USER->max_last_name+1)." characters<br>";
-        unset($_POST["last_name"]);
-    }
-    if (strlen($user->last_name) < $VAL_USER->min_last_name) {
-        $error = $error."Last Name has to be bigger than ".($VAL_USER->min_last_name-1)." characters<br>";
-        unset($_POST["last_name"]);
-    }
-    if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\ 0-9]/',$user->last_name)) {
-        $error = $error."The last name cannot contain special characters or numbers<br>";
-        unset($_POST["last_name"]);
-    }
-
-
-    if (ldap_mail_count($user->email)) {
-        $error = $error."This email is already has an account. Did you forget your password?<br>";
-        unset($_POST["email"]);
-    }
-    if (!filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
-        $error = $error."Invalid email format<br>";
-        unset($_POST["email"]);
-    }elseif(in_array(explode("@", $user->email)[1], $MAIL_HOST_BLACKLIST )){
-        $error = $error."This email service is not allowed<br>";
-        unset($_POST["email"]);
-    }
-    $pending = redis_get("pending");
-    if ($pending){
-        $maillist = $pending->mails;
-        if (in_array($user->email, $maillist)){
-            $error = $error."This email is already pending approval, check your mailbox or try to register with a different email<br>";
-            unset($_POST["email"]);
-        }
-    }
-
-
-    if ($_POST["password"] != $_POST["password_confirm"]) {;
-        $error = $error."Passwords do not match!<br>";
-        unset($_POST["password_confirm"]);
-    }
+    include_once 'validators.php';
+    include_once $TEMPLATE.'/strings.php';
     $password = $_POST["password"];
-    if (strlen($password) < $VAL_USER->min_password) {
-        $error = $error."Password should have at least ".$VAL_USER->min_password." characters<br>";
-        unset($_POST["password"]);
-        unset($_POST["password_confirm"]);
-    }
-    if (strlen($password) > $VAL_USER->max_password) {
-        $error = $error."Your password is too big!<br>";
-        unset($_POST["password"]);
-        unset($_POST["password_confirm"]);
-    }
-    include "blacklists/password.php";
-    if(in_array($password, $PASSWORD_BLACKLIST)) {
-        $error = $error."That password is not allowed!<br>";
-        unset($_POST["password"]);
-        unset($_POST["password_confirm"]);
-    }
-    foreach (array("username", "name", "last_name", "email") as &$field) {
-        if (!isset($_POST[$field]))
-            continue;
-        $value = strtoupper($_POST[$field]);
-        $PASSWORD = strtoupper($password);
-        if(strpos($value, $PASSWORD) !== false || strpos($PASSWORD, $value) !== false){
-            $error = $error."Your password cannot contain any of your names or email neither the names can contain the password<br>";
-            unset($_POST["password"]);
-            unset($_POST["password_confirm"]);
-            break;
-        }
-    }
+    $error = "";
+
+    $error .= validate_username($user->user_name);
+    $error .= validate_name($user->name, $FIRST_NAME_VALIDATION_ERROR);
+    $error .= validate_name($user->last_name, $LAST_NAME_VALIDATION_ERROR);
+    $error .= validate_email($user->email);
+    $error .= validate_password($password);
+
 
     if (!(isset($_SESSION['captcha']) && PhraseBuilder::comparePhrases($_SESSION['captcha'], $_POST['captcha']))) {
         $error = $error."Wrong captcha!<br>";
@@ -179,8 +77,10 @@
 
 function approve_request($user){
     include "mail.php";
-    echo "<h2>Almost there! Confirm your email</h2>";
-    $token = generateRandomString();
+    $token = "";
+    do {
+        $token = generateRandomString();
+    } while (redis_get($token));
     redis_set($token, $user, $MAIL_CONFIRMATION_AWAIT_DELAY);
     $pending = redis_get("pending");
     if ($pending){
@@ -204,12 +104,12 @@
     $_SESSION['resend'] = generateRandomString(12);
     $_SESSION['token'] = $token;
     $_SESSION['email'] = $user->email;
-    echo "<p>Didn't receive anything yet? <a href='".$BASE_URL."/?type=resend&token=".$_SESSION['resend']."'>Click here</a> to resend the confirmation email.</p>";
+    include $TEMPLATE."confirm_your_email.htm";
 }
 
 
 // PAGE
-include "html/header.htm";
+include $TEMPLATE."/header.htm";
 
 if ($_SERVER["REQUEST_METHOD"] == "POST") {
     include 'ldap.php';
@@ -218,7 +118,7 @@
             case "register":
                 $user = new User($_POST["username"], $_POST["name"], $_POST["last_name"], $_POST["email"], $_POST["password"]); 
                 if (redis_inc_ipdata(getClientIP(), "register", true) > $HOURLY_REGISTRATIONS){
-                    include "html/registration_limit.htm";
+                    include $TEMPLATE."/registration_limit.htm";
                 }else{
                     $error = verify_request($user);
                     if ($error)
@@ -227,13 +127,15 @@
                         approve_request($user);
                 }
                 break;
+            case "recover":
+                break;
         }
     }
 } elseif (isset($_GET['type'])) {
     switch ($_GET['type']) {
         case "confirmation":
             if (!isset($_GET["token"])){
-                echo "INVALID REQUEST!";
+                echo $RUNTIME_ERROR->user_trying_invalid_get;
             }else{
                 include "ldap.php";
                 $token = $_GET["token"];
@@ -252,22 +154,22 @@
                             }
                         }
                         redis_inc_ipdata(getClientIP(), "register");
-                        echo "<h1>Email Confirmation</h1>";
-                        include "html/mail_confirmed.htm";
+                        echo $STRINGS->email_confirmation;
+                        include $TEMPLATE."/mail_confirmed.htm";
                     }else{
-                        echo "<h1>Email Confirmation</h1>";
-                        include "html/registration_error.htm";
+                        echo $STRINGS->email_confirmation;
+                        include $TEMPLATE."/registration_error.htm";
                     }
                     redis_delete($token);
                 }else{
-                    include "html/token_expired.htm";
+                    include $TEMPLATE."/token_expired.htm";
                 }
             }
             break;
         case "resend":
             if (isset($_GET['token']) && isset($_SESSION['resend']) && $_GET['token'] == $_SESSION['resend']){
                 include "mail.php";
-                include "html/resend_mail.htm";
+                include $TEMPLATE."/resend_mail.htm";
                 $token = $_SESSION['token'];
                 $url = $BASE_URL."?type=confirmation&token=".$token;
                 $smtp = $FALLBACK_SMTP;
@@ -282,6 +184,10 @@
                 unset($_SESSION['email']);
             }
             break;
+        case "recover":
+            break;
+        case "confirm_recover":
+            break;
     }
 
 
@@ -290,5 +196,5 @@
     register_page();
 }
 
-include "html/bottom.htm";
+include $TEMPLATE."/bottom.htm";
 ?>
diff --git a/html/bottom.htm b/templates/bottom.htm
similarity index 100%
rename from html/bottom.htm
rename to templates/bottom.htm
diff --git a/templates/confirm_your_email.htm b/templates/confirm_your_email.htm
new file mode 100644
index 0000000..0b7d855
--- /dev/null
+++ b/templates/confirm_your_email.htm
@@ -0,0 +1,5 @@
+<h2>Almost there! Confirm your email</h2>
+
+<?php 
+echo "<p>Didn't receive anything yet? <a href='".$BASE_URL."/?type=resend&token=".$_SESSION['resend']."'>Click here</a> to resend the confirmation email.</p>"; 
+?>
diff --git a/html/error.htm b/templates/error.htm
similarity index 100%
rename from html/error.htm
rename to templates/error.htm
diff --git a/html/header.htm b/templates/header.htm
similarity index 100%
rename from html/header.htm
rename to templates/header.htm
diff --git a/html/mail_confirmed.htm b/templates/mail_confirmed.htm
similarity index 100%
rename from html/mail_confirmed.htm
rename to templates/mail_confirmed.htm
diff --git a/html/register.htm b/templates/register.htm
similarity index 100%
rename from html/register.htm
rename to templates/register.htm
diff --git a/html/registration_error.htm b/templates/registration_error.htm
similarity index 100%
rename from html/registration_error.htm
rename to templates/registration_error.htm
diff --git a/html/registration_limit.htm b/templates/registration_limit.htm
similarity index 100%
rename from html/registration_limit.htm
rename to templates/registration_limit.htm
diff --git a/html/resend_mail.htm b/templates/resend_mail.htm
similarity index 100%
rename from html/resend_mail.htm
rename to templates/resend_mail.htm
diff --git a/templates/strings.php b/templates/strings.php
new file mode 100644
index 0000000..91e1d86
--- /dev/null
+++ b/templates/strings.php
@@ -0,0 +1,52 @@
+<?php
+$RUNTIME_ERROR = (object)[
+        "template_not_found" => "Either you did not create the folder {{template}} or strings.php is missing on it. Maybe you have set {{langcc}} wrong on config.php?",
+        "user_trying_invalid_get" => "INVALID REQUEST. THERE IS NOTHING HERE FOR YOU",
+];
+
+$USERNAME_VALIDATION_ERROR = (object)[
+        "registered" => "This username is already in use! Please choose another username<br>",
+        "no_whitespaces" => "Username cannot contain whitespaces<br>",
+        "smaller_than" => "Username must have less than {{num}} characters<br>",
+        "bigger_than" => "Username must be bigger than {{num}} characters<br>",
+        "no_special_chars" => "The username cannot contain special characters<br>",
+        "no_number_begining" => "The username cannot begin with a number<br>",
+        "blacklisted" => "That Username is not allowed!<br>",
+];
+
+$FIRST_NAME_VALIDATION_ERROR = (object)[
+        "no_whitespaces" => "First name cannot contain whitespaces<br>",
+        "smaller_than" => "First name must have less than {{num}} characters<br>",
+        "bigger_than" => "First name must be bigger than {{num}} characters<br>",
+        "no_special_chars" => "The first name cannot contain special characters or numbers<br>",
+];
+
+$LAST_NAME_VALIDATION_ERROR = (object)[
+        "no_whitespaces" => "Last name cannot contain whitespaces<br>",
+        "smaller_than" => "Last name must have less than {{num}} characters<br>",
+        "bigger_than" => "Last name must be bigger than {{num}} characters<br>",
+        "no_special_chars" => "The last name cannot contain special characters or numbers<br>",
+];
+
+$EMAIL_VALIDATION_ERROR = (object)[
+        "registered" => "This email is already belongs to an account. Did you <a href='{{link}}'>forget your password?</a><br>",
+        "invalid" => "Invalid email format<br>",
+        "blacklisted" => "This email service is not allowed<br>",
+        "pending" => "This email is already pending approval, check your mailbox or try to register with a different email<br>",
+
+];
+
+$PASSWORD_VALIDATION_ERROR = (object)[
+        "no_match" => "Passwords do not match!<br>",
+        "bigger_than" => "Password should have at least {{num}} characters<br>",
+        "smaller_than" => "Password is too big. Should have at max {{num}} characters<br>",
+        "blacklisted" => "That password is not allowed!<br>",
+        "shared_inclusion" => "Your password cannot contain any of your names or email neither the names can contain the password<br>"
+];
+
+$STRINGS = (object)[
+        "email_confirmation" => "<h1>Email Confirmation</h1>",
+        "reloading_captcha" => "Loading...",
+];
+
+?>
diff --git a/html/token_expired.htm b/templates/token_expired.htm
similarity index 100%
rename from html/token_expired.htm
rename to templates/token_expired.htm
diff --git a/utils.php b/utils.php
index c3a9620..6086153 100644
--- a/utils.php
+++ b/utils.php
@@ -1,5 +1,6 @@
 <?php
-function generateRandomString($length = 96) {
+function generateRandomString($length = 96)
+{
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $charactersLength = strlen($characters);
     $randomString = '';
@@ -9,16 +10,21 @@
     return $randomString;
 }
 
-function getClientIP():string
+function getClientIP(): string
 {
-    $keys=array('HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR');
-    foreach($keys as $k)
-    {
-        if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP))
-        {
+    $keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
+    foreach ($keys as $k) {
+        if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP)) {
             return $_SERVER[$k];
         }
     }
     return false;
 }
-?>
+
+function format(string $string, array $values)
+{
+    foreach ($values as $key => $value) {
+        $string = str_replace("{{{$key}}}", $value, $string);
+    }
+    return $string;
+}
diff --git a/validators.php b/validators.php
new file mode 100644
index 0000000..4bcbe42
--- /dev/null
+++ b/validators.php
@@ -0,0 +1,140 @@
+<?php
+include_once'ldap.php';
+include_once'redis.php';
+include_once'config.php';
+include_once'utils.php';
+
+$INCLUDE_STRINGS_PATH = "templates_".$LANG_CC;
+if (isset($LANG_CC) && !empty($LANG_CC)) $TEMPLATE = $INCLUDE_STRINGS_PATH;
+else $TEMPLATE = "templates";
+
+
+function validate_username(string $username)
+{
+        include_once'config.php';
+        include_once$TEMPLATE.'/strings.php';
+        $error = "";
+        if (ldap_user_count($username)) {
+                $error = $error . $USERNAME_VALIDATION_ERROR->registered;
+                unset($_POST["username"]);
+        }
+        if (preg_match("/\s/", $username)) {
+                $error = $error . $USERNAME_VALIDATION_ERROR->no_whitespaces;
+                unset($_POST["username"]);
+        }
+        if (strlen($username) > $VAL_USER->max_username) {
+                $error = $error . format($USERNAME_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_username + 1]);
+                unset($_POST["username"]);
+        }
+        if (strlen($username) < $VAL_USER->min_username) {
+                $error = $error . format($USERNAME_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_username - 1]);
+                unset($_POST["username"]);
+        }
+        if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $username)) {
+                $error = $error . $USERNAME_VALIDATION_ERROR->no_special_chars;
+                unset($_POST["username"]);
+        }
+        if (preg_match('/^\d/', $username)) {
+                $error = $error . $USERNAME_VALIDATION_ERROR->no_number_begining;
+                unset($_POST["username"]);
+        }
+        include_once"blacklists/usernames.php";
+        if (in_array($username, $USERNAME_BLACKLIST)) {
+                $error = $error . $USERNAME_VALIDATION_ERROR->blacklisted; 
+                unset($_POST["username"]);
+        }
+        return $error;
+}
+
+function validate_name(string $name, object $ERRORS)
+{
+        include_once "config.php";
+        include_once$TEMPLATE.'/strings.php';
+        $error = "";
+        if (preg_match("/\s/", $name)) {
+                $error = $error . $ERRORS->no_whitespaces;
+                unset($_POST["name"]);
+        }
+        if (strlen($name) > $VAL_USER->max_first_name) {
+                $error = $error . format($ERRORS->smaller_than, ["num" => $VAL_USER->max_first_name + 1]);
+                unset($_POST["name"]);
+        }
+        if (strlen($name) < $VAL_USER->min_first_name) {
+                $error = $error . format($ERRORS->bigger_than, ["num" => $VAL_USER->min_first_name - 1]);
+                unset($_POST["name"]);
+        }
+        if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\0-9]/', $name)) {
+                $error = $error . $ERRORS->no_special_chars;
+                unset($_POST["name"]);
+        }
+        return $error;
+}
+
+function validate_email(string $email)
+{
+        include_once "config.php";
+        include_once$TEMPLATE.'/strings.php';
+        $error = "";
+
+        if (ldap_mail_count($email)) {
+                $error = $error . format($EMAIL_VALIDATION_ERROR->registered, ["link" => $BASE_URL."?type=recover"]);
+                unset($_POST["email"]);
+        }
+        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
+                $error = $error . $EMAIL_VALIDATION_ERROR->invalid;
+                unset($_POST["email"]);
+        } elseif (in_array(explode("@", $email)[1], $MAIL_HOST_BLACKLIST)) {
+                $error = $error . $EMAIL_VALIDATION_ERROR->blacklisted;
+                unset($_POST["email"]);
+        }
+        $pending = redis_get("pending");
+        if ($pending) {
+                $maillist = $pending->mails;
+                if (in_array($email, $maillist)) {
+                        $error = $error . $EMAIL_VALIDATION_ERROR->pending;
+                        unset($_POST["email"]);
+                }
+        }
+        return $error;
+}
+
+
+function validate_password(string $password)
+{
+        include_once "config.php";
+        include_once$TEMPLATE.'/strings.php';
+        $error = "";
+        if ($_POST["password"] != $_POST["password_confirm"]) {;
+                $error = $error . $PASSWORD_VALIDATION_ERROR->no_match;
+                unset($_POST["password_confirm"]);
+        }
+        if (strlen($password) < $VAL_USER->min_password) {
+                $error = $error . format($PASSWORD_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_password]);
+                unset($_POST["password"]);
+                unset($_POST["password_confirm"]);
+        }
+        if (strlen($password) > $VAL_USER->max_password) {
+                $error = $error . format($PASSWORD_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_password]);
+                unset($_POST["password"]);
+                unset($_POST["password_confirm"]);
+        }
+        include_once"blacklists/password.php";
+        if (in_array($password, $PASSWORD_BLACKLIST)) {
+                $error = $error . $PASSWORD_VALIDATION_ERROR->blacklisted;
+                unset($_POST["password"]);
+                unset($_POST["password_confirm"]);
+        }
+        foreach (array("username", "name", "last_name", "email") as &$field) {
+                if (!isset($_POST[$field]))
+                        continue;
+                $value = strtoupper($_POST[$field]);
+                $PASSWORD = strtoupper($password);
+                if (strpos($value, $PASSWORD) !== false || strpos($PASSWORD, $value) !== false) {
+                        $error = $error . $PASSWORD_VALIDATION_ERROR->shared_inclusion;
+                        unset($_POST["password"]);
+                        unset($_POST["password_confirm"]);
+                        break;
+                }
+        }
+        return $error;
+}