Jump to content

homar

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

homar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello! I'm trying to create a global array in my script that can then be accessed and modified in my class methods. E.g: <<< START: script.php >>> include("classes/someclass.php"); $var = array(); array_push($var, "value"); $obj = someclass::someMethod(); print_r($var); ### Need this to output: ARRAY([0] => "value", [1] => "another value") <<< END: script.php >>> <<< START: someclass.php >>> class someclass { public function someMethod() { array_push($var, "another value"); ### How can I update the value of $var here in this class } } <<< END: someclass.php >>> Hopefully, you get the idea. Thanks for your help!
  2. Hi PFMaBiSmAd! Thanks for that. Do you know how I can change these settings without php.ini access. I know you can use error_reporting(E_ALL);, but should I put this in my script or the class?
  3. Thanks Aaron! I actually had it like that originally. It still doesn't output anything. Also, when I place: echo "test"; above the include, "test" is output. However, if I put it after the include, nothing is displayed.
  4. Thanks Snart! I tried your code, but it didn't make a difference. No error message. Nothing
  5. Sure, It's kind of long though... <?php ## Change these settings as you please $options = array ( "minLength" => 4, ## minimum allowable password length (int) "maxLength" => 100, ## maximum allowable password length (int) "securePass" => "ir2#cT@d", ## a password that scores 100% (string) "dictionary" => true, ## check dictionary? (bool) "caseSensitive" => true ## does your script accept case sensitive passwords? (bool) ); ## Include required files include('./classes/dictionary.php'); include('./classes/algorithm.php'); ## Password $password = $_REQUEST['pass']; ## Username $username = $_REQUEST['user']; ## Split password into words by numbers (e.g. password1 or 1password is no good) $parts = array_filter(preg_split('/[^a-zA-Z]/',$password)); ## Array to contain identifiable words $words = array(); ## Check the dictionary foreach ($parts as $word) { ## Prevent letters and common combinations being matched if (strlen($word) > 3) { if(SpellChecker::Check(strtolower($word))) { $containsWord = true; ## password contains word $words = array_push($words, $word); ## add identifiable word to array } } } ## Execute the algorithm PasswordStrength::Score($password, $options, $containsWord, $words, $username); ## Output the score echo ($score); ?> <?php class PasswordStrength { ## Constructor private function __construct() {} ## Calculates the number of 1 to n letter words private function numWords($length) { ## The number of english words with n-letters $nLetterWords = array ( "1" => "26", "2" => "99", "3" => "994", "4" => "3957", "5" => "8801", "6" => "15553", "7" => "23674", "8" => "29302", "9" => "24811", "10" => "20192", "11" => "15404", "12" => "11271", "13" => "7780", "14" => "5099", "15" => "3175", "16" => "1942", "17" => "1127", "18" => "595", "19" => "328", "20" => "160", "21" => "62", "22" => "31", "23" => "13", "24" => "9", "25" => "2", "26" => "0", "27" => "2", "27" => "2" ); $i = 1; while ($i < $length) { $numWords += $nLetterWords($i); $i++; } return $numWords; } ## Brute force procedure private function brute($password) { ## Length of the password $passLength = strlen($password); ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Identify whether the password contains numbers preg_match_all('/[0-9]/', $password, $numbers); if (!empty($numbers)) { $numbers = count($numbers[0]); } else { $numbers = 0; } ## Identify whether the password contains symbols preg_match_all('/[^a-zA-Z0-9]/', $password, $symbols); if (!empty($symbols)) { $symbols = count($symbols[0]); } else { $symbols = 0; } ## Initialize diversity $diversity = 0; ## Case sensitivity, lower case if ((($lowercase > 0) && ($options['caseSensitive'])) { $diversity += 26; } ## Case sensitivity, upper OR lower case if (($uppercase > 0) && ($options['caseSensitive'])) { $diversity += 26; } ## No case sensitivity if (!$options['caseSensitive']) { $diversity += 26; } ## Numbers if ($numbers > 0) { $diversity += 10; } ## Symbols: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ if ($symbols > 0) { $diversity += 32; } $score = ceil(pow($diversity, $passLength)*0.5); return $score; } ## Score the password public function Score($password, $options, $containsWord, $words, $username=NULL) { ## $password: the password to analyse (string) ## $options: execution configuration options (array) ## $containsWord: does the password contain a easily identifiable word (bool) ## $words: array containing identifiable words (array) ## $username: user's username (string) ## Length of the password $passLength = strlen($password); ## Length of the identifiable words $wordsLength = strlen(implode('', $words)); ## Number of words with length 1 to n $numWords = numWords($wordsLength); ## Identify whether the password is a single "real" word if (($containsWord) && ($wordsLength == $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0)) || (($lowercase == 0) && ($uppercase > 0)) { ## Only upper case OR only lower case $score = ceil($numWords*0.5); } else { ## Upper case AND lower case $score = ceil(($numWords*0.5) * pow(2, $passLength)); } } else { $score = ceil($numWords*0.5); } } ## Any identifiable words with suffix or prefix elseif (($containsWord) && ($wordsLength != $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0)) || (($lowercase == 0) && ($uppercase > 0)) { ## Only upper case OR only lower case $score = ceil(($numWords*0.5) + brute(str_replace($words, "", $password))); } else { ## Upper case AND lower case $score = ceil((($numWords*0.5) * pow(2, $passLength)) + brute(str_replace($words, "", $password))); } } else { $score = ceil($numWords*0.5); } } ## Use brute force procedure else { $score = brute($password); } return $score; } } ?>
  6. Sorry! I should have mentioned that I used: ClassName::Function($var);
  7. Hello! I'm new to working with classes and object (basically the whole OOP thing). I've written a class and placed it in a file (someclass.php). When I include the class from my script using: include('someclass.php'); Nothing is displayed when I load the script (just a white page). I figure that there must be an error in my class. However, no error messages are output. If I don't include the class file (and intentionally create an error), error messages are displayed. Basically, is there a way to debug the class? Thanks for your help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.