Sicrit Society

connect(true)) { $mqtt->publish($topic, $logline, 0, 0); //echo "Published message: " . $message; $mqtt->close(); }else{ //echo "Fail or time out
"; } } function checkPassword($username, $dateStr, $password) { global $debug; $failed = false; $stageFailed = 0; if (!checkLength($password)) { $failed = true; $stageFailed = 1; if (!$debug) { return $stageFailed; } } if (!checkSpecialChars($password)) { $failed = true; $stageFailed = 2; if (!$debug) { return $stageFailed; } } if (!hasPalindrome($password)) { $failed = true; $stageFailed = 3; if (!$debug) { return $stageFailed; } } if (!hasPrimeLength($password)) { $failed = true; $stageFailed = 4; if (!$debug) { return $stageFailed; } } if (!checkInPI($password)) { $failed = true; $stageFailed = 5; if (!$debug) { return $stageFailed; } } if (!checkUserInPassword($username, $password)) { $failed = true; $stageFailed = 6; if (!$debug) { return $stageFailed; } } if (!hasAnimal($password)) { $failed = true; $stageFailed = 7; if (!$debug) { return $stageFailed; } } if (!isSentence($password)) { $failed = true; $stageFailed = 8; if (!$debug) { return $stageFailed; } } if (!hasWords($password)) { $failed = true; $stageFailed = 9; if (!$debug) { return $stageFailed; } } if (!checkSameLetterWords($password)) { $failed = true; $stageFailed = 10; if (!$debug) { return $stageFailed; } } if (!hasUniqueWords($password)) { $failed = true; $stageFailed = 11; if (!$debug) { return $stageFailed; } } if (!hasZodiacSign($password, $dateStr)) { $failed = true; $stageFailed = 12; if (!$debug) { return $stageFailed; } } if (!checkEnclosedCount($password)) { $failed = true; $stageFailed = 13; if (!$debug) { return $stageFailed; } } if (!hasEiffelSteps($password)) { $failed = true; $stageFailed = 14; if (!$debug) { return $stageFailed; } } if (!lowLetterNumberSum($password)) { $failed = true; $stageFailed = 15; if (!$debug) { return $stageFailed; } } if (!hasNotHadBirthday($dateStr)) { $failed = true; $stageFailed = 16; if (!$debug) { return $stageFailed; } } if (!$failed) { echo "

You are now successfully signed up! Be patient while we implement the login functionality... Meanwhile. Have a 'Raspberry'!

"; } return $stageFailed; } function checkLength($password) { echo "

Password must have more than 6 characters ... "; if (strlen($password) <= 6) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function checkSpecialChars($password) { echo "

Password must include special characters ... "; if (!preg_match('/[^\da-zA-Z]/', $password)) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function hasPalindrome($password) { echo "

Password must include something resembling a palindrome ... "; $words = preg_split('/\s+/', $password); foreach ($words as $word) { if ($word == strrev($word)) { echo "[OK]

"; return true; } } echo "[FAIL]"; return false; } function hasPrimeLength($password) { $primes = array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997); echo "

Password length must be prime ... "; global $verbose; if ($verbose) { echo 'VERBOSE: length: ' . strlen($password) . ', primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601'; } if (!in_array(strlen($password), $primes)) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function checkInPI($password) { echo "

Password must contain any decimal of pi, but not the number 9 ... "; if (strpos($password, "9") !== false) { echo "[FAIL]

"; return false; } for ($i=0; $i[OK]"; return true; } } echo "[FAIL]"; return false; } function checkUserInPassword($username, $password) { echo "

The password must include your username ... "; if (strpos($password, $username) === false) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function hasAnimal($password) { $animals = array("alligator", "ant", "bear", "bee", "bird", "camel", "cat", "cheetah", "chicken", "chimpanzee", "cow", "crocodile", "deer", "dog", "dolphin", "duck", "eagle", "elephant", "fish", "fly", "fox", "frog", "giraffe", "goat", "goldfish", "hamster", "hippopotamus", "horse", "kangaroo", "kitten", "lion", "lobster", "monkey", "octopus", "owl", "panda", "pig", "puppy", "rabbit", "rat", "scorpion", "seal", "shark", "sheep", "snail", "snake", "spider", "squirrel", "tiger", "turtle", "wolf", "zebra"); echo "

Password must include an average size animal ... "; global $verbose; if ($verbose) { echo 'VERBOSE: accepted animals: "alligator", "ant", "bear", "bee", "bird", "camel", "cat", "cheetah", "chicken", "chimpanzee", "cow", "crocodile", "deer", "dog", "dolphin", "duck", "eagle", "elephant", "fish", "fly", "fox", "frog", "giraffe", "goat", "goldfish", "hamster", "hippopotamus", "horse", "kangaroo", "kitten", "lion", "lobster", "monkey", "octopus", "owl", "panda", "pig", "puppy", "rabbit", "rat", "scorpion", "seal", "shark", "sheep", "snail", "snake", "spider", "squirrel", "tiger", "turtle", "wolf", "zebra". '; } foreach($animals as $animal) { if (strpos(strtolower($password), $animal) !== false) { echo "[OK]

"; return true; } } echo "[FAIL]"; return false; } function isSentence($password) { echo "

Password must seem like a sentence ... "; if (!preg_match('~^\p{Lu}~u', $password[0])) { echo "[FAIL]

"; return false; } if ($password[strlen($password) - 1] !== "." && $password[strlen($password) - 1] !== "?" && $password[strlen($password) - 1] !== "!") { echo "[FAIL]"; return false; } echo "[OK]"; return true; } function hasWords($password) { echo "

Password must include at least six words ... "; $words = preg_split('/\s+/', $password); global $verbose; if ($verbose) { echo 'VERBOSE: words: ' . count($words) . ' '; } if (count($words) < 6) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function checkSameLetterWords($password) { echo "

All words in the password must start with the same letter... "; $lowerpw = strtolower($password); $words = preg_split('/\s+/', $lowerpw); $letter = $lowerpw[0]; foreach ($words as $word) { if ($word[0] !== $letter) { echo "[FAIL]

"; return false; } } echo "[OK]"; return true; } function hasUniqueWords($password) { echo "

All words in the password must be unique ... "; if (str_word_count($password, 0) !== count(array_unique(str_word_count($password, 1)))) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function hasZodiacSign($password, $dateStr) { echo "

Password must include your zodiac sign ... "; $zodiacSign = zodiac($dateStr); if ($zodiacSign == "") { echo "[FAIL]

"; return false; } //$words = preg_split('/\s+/', strtoupper($password)); $words = preg_split('/[\W]/', strtoupper($password)); global $verbose; if ($verbose) { echo 'VERBOSE: zodiac: ' . $zodiacSign . ' '; //print_r($words); } if (in_array(strtoupper($zodiacSign), $words)) { echo "[OK]"; return true; } echo "[FAIL]"; return false; } function zodiac($dateStr) { $date = date_parse($dateStr); $month = $date['month']; $day = $date['day']; if (!$month || !$day) { return false; } $zodiac = array('', 'capricorn', 'aquarius', 'pisces', 'aries', 'taurus', 'gemini', 'cancer', 'leo', 'virgo', 'libra', 'scorpio', 'sagittarius', 'capricorn'); $last_day = array('', 19, 18, 20, 20, 21, 21, 22, 22, 21, 22, 21, 20, 19); return ($day > $last_day[$month]) ? $zodiac[$month + 1] : $zodiac[$month]; } function checkEnclosedCount($password) { $encloses = array( 'A' => 1, 'B' => 2, 'D' => 1, 'O' => 1, 'P' => 1, 'Q' => 1, 'R' => 1, 'a' => 1, 'b' => 1, 'd' => 1, 'e' => 1, 'g' => 1, 'o' => 1, 'p' => 1, 'q' => 1, '0' => 1, '4' => 1, '6' => 1, '8' => 2, '9' => 1 ); $numberCount = 0; $encloseCount = 0; for ($i=0; $iThe number of enclosed areas (a=1,b=1,c=0...) in the letters and numbers must equal the amount of numbers... "; global $verbose; if ($verbose) { echo 'VERBOSE: numbercount: ' . $numberCount . ', enclosedCount: ' . $encloseCount . ' '; } if ($numberCount != $encloseCount) { echo "[FAIL]"; return false; } echo "[OK]"; return true; } function hasEiffelSteps($password) { echo "

The password must include the number of steps in the eiffel tower ... "; global $verbose; if ($verbose) { echo 'VERBOSE: 1710'; } if (strpos($password, "1710") === false) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function lowLetterNumberSum($password) { echo '

The letter number sum must be less than 145 (a=1 ... z=26)... '; $sum = letterNumberSum($password); if ($sum >= 145 && $sum < 300) { echo 'Hint: You currently have ' . $sum . '! '; } if ($sum >= 145 ) { echo "[FAIL]

"; return false; } echo "[OK]"; return true; } function letterNumberSum($word) { $cnt = 0; $word = strtoupper(trim($word)); $len = strlen($word); for($i = 0; $i < $len; $i++) { if (ord($word[$i]) > 64 && ord($word[$i]) < 91) { // only count actual letters $cnt += ord($word[$i]) - 64; } } global $verbose; if ($verbose) { echo 'VERBOSE: ' . $cnt . ' '; } return $cnt; } function hasNotHadBirthday($dateStr) { echo "

You must not have had your birthday this year ... "; $date = date_parse($dateStr); $month = $date['month']; $day = $date['day']; if (!$month || !$day) { echo "[FAIL]

"; return false; } if (!(($month == 11 && $day > 27) || $month == 12)) { echo "[FAIL]"; return false; } echo "[OK]"; return true; } ?>