Jump to content

[SOLVED] No error messages after including a class


Recommended Posts

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!

just loading a class doesn't do anything....you need to initiate an instance of it for any of the code in it to actually run.

 

<?php
require_once('someclass.php'); //use require_once instead to make sure it loads and only loads once
$obj = new someclass();
print_r($obj);
?>

 

seriously...premiso...this is starting to scare me

just loading a class doesn't do anything....you need to initiate an instance of it for any of the code in it to actually run.

 

<?php
require_once('someclass.php'); //use require_once instead to make sure it loads and only loads once
$obj = new someclass();
print_r($obj);
?>

 

seriously...premiso...this is starting to scare me

 

lol at least you gave an example :( I guess I could have been nice and done that too lol.

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;

}

}

 

?>

calling it statically like you had is fine...but you aren't storing the return value into $score...it should be like so:

$score = PasswordStrength::Score($password, $options, $containsWord, $words, $username);

 

p.s. - next time you post code, use [ code ][ /code ] tags (without the spaces)...clicking the button in the toolbar with the # sign does the same thing

Blank pages are usually the result of fatal parse or fatal runtime errors (or pages that don't output anything.) In your case, you have a fatal parse error -

 

Parse error: parse error in ...\algorithm.php on line 97

 

It looks like a mis-match of ((( and ))

 

You should be learning php (or learning something new in php), developing php code, and debugging php code on a system where error_reporting is set to E_ALL and display_errors is set to ON in your php.ini to get php to help you (fatal parse errors won't be displayed if you try to turn these settings on in your script.)

 

Edit: and after you fix that error, there is another one at line 166 in that file.

 

Edit2: and another one at line 201.

 

Php error reporting is there to help you. It will save a ton of time.

For fatal parse errors, the settings must be on before your script is parsed.

 

You should be learning, developing, and debugging on a local development system on your PC where you would have access to the php.ini.

 

If php is running as an Apache module, you can put the equivalent settings in a .htaccess file. the E_ALL must be converted to the corresponding integer value because the constant E_ALL does not exist at the .htaccess level.

 

If php is running as a CGI application, you can put the settings in a local php.ini.

I think i got all your issues...i made comments where i made changes:

<?php
class PasswordStrength
{
   ## Constructor
   private function __construct() {}
   
   ## Calculates the number of 1 to n letter words
   private static function numWords($length) //Made this function static
   {
      ## 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 static function brute($password) //Made this function static
   {
      ## 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']))) { //Missing a Left Parenthesis here
         $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 static function Score($password, $options, $containsWord, $words, $username=NULL) //Made this function static
   {
      ## $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 = self::numWords($wordsLength); //Added self:: here
      
      ## 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))) //Missplaces Parenthesis here
            {
               ## 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))) //Misplaced Parenthesis here
            {
               ## Only upper case OR only lower case
               $score = ceil(($numWords*0.5) + self::brute(str_replace($words, "", $password))); //Needed self:: here
            } else {
               ## Upper case AND lower case
               $score = ceil((($numWords*0.5) * pow(2, $passLength)) + self::brute(str_replace($words, "", $password))); //Needed self:: here
            }
         } else {
            $score = ceil($numWords*0.5);
         }
      }
      
      ## Use brute force procedure
      else
      {
         $score = self::brute($password); //Needed self:: here
      }
      
      return $score;
   }
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.