Skip to content

Commit 6aca263

Browse files
Enrico SolaEnrico Sola
authored andcommitted
Removed "dirname" allowing to use both relative and absolute paths.
1 parent 4ab7a93 commit 6aca263

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ryanj93/php-password-toolbox",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "A simple toolkit for generate, analyse and hash passwords with PHP.",
55
"type": "library",
66
"license": "GPL-3.0-or-later",

demo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
echo 'Random password: ' . $password . PHP_EOL;
88

99
//Generating a human readable password.
10-
$psw = $generator->setDictionaryPath('dictionary.txt')->generateHumanReadable(12, 2);
10+
$psw = $generator->setDictionaryPath(dirname(__FILE__) . '/dictionary.txt')->generateHumanReadable(12, 2);
1111
echo 'Human readable password: ' . $psw . PHP_EOL;
1212

1313
//Analyzing password.
@@ -16,7 +16,7 @@
1616
var_dump($analysis);
1717

1818
//Complete password analysis.
19-
$analysis = $analyzer->setDictionaryPath('rockyou.txt')->completeAnalysis($password);
19+
$analysis = $analyzer->setDictionaryPath(dirname(__FILE__) . '/rockyou.txt')->completeAnalysis($password);
2020
var_dump($analysis);
2121

2222
//Creating a hash from the password.

php-password-toolbox.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function readFileChunk(string $path, int $chunkSize = NULL, int $p
6363
$start = 0;
6464
}
6565
$length = $chunkSize + self::MAX_SIZE_CHARACTER;
66-
$data = @file_get_contents(dirname(__FILE__) . '/' . $path, false, NULL, $start, $length);
66+
$data = @file_get_contents($path, false, NULL, $start, $length);
6767
if ( $data === false ){
6868
throw new \Exception('Unable to read from the given file.');
6969
}
@@ -178,7 +178,7 @@ public function loadDictionaryCache(): bool{
178178
if ( $this->cache === false || $this->dictionary === NULL ){
179179
return false;
180180
}
181-
$data = @file_get_contents(dirname(__FILE__) . '/' . $this->dictionary);
181+
$data = @file_get_contents($this->dictionary);
182182
if ( $data === false ){
183183
throw new \Exception('Unable to load the dictionary.');
184184
}
@@ -256,8 +256,8 @@ public function getDictionaryEncoding(): string{
256256
/**
257257
* Analyzes a given password.
258258
*
259-
* @param string password The password to analyze.
260-
* @param array keywords An optional sequeantial array of strings containing some keywords which shall be looked into the given password (like first name, surname, e-mail address and so on).
259+
* @param string $password The password to analyze.
260+
* @param array $keywords An optional sequeantial array of strings containing some keywords which shall be looked into the given password (like first name, surname, e-mail address and so on).
261261
*
262262
* @return array An associative array containing the information of the analysis, like chars counts, keywords counts and strength score.
263263
*/
@@ -341,8 +341,8 @@ public function analyze(string $password, array $keywords = NULL): array{
341341
/**
342342
* Analyzes a given password using also a dictionary of weak passwords to test its strength.
343343
*
344-
* @param string password The password to analyze.
345-
* @param array info A sequential array of strings containing some additional information which shall be looked into the given password (like first name, surname, e-mail address and so on).
344+
* @param string $password The password to analyze.
345+
* @param array $info A sequential array of strings containing some additional information which shall be looked into the given password (like first name, surname, e-mail address and so on).
346346
*
347347
* @return array An associative array containing the information of the analysis, like chars counts, keywords counts and strength score.
348348
*/
@@ -369,7 +369,7 @@ public function completeAnalysis(string $password, array $keywords = NULL): arra
369369
$analysis['score'] = (int)$analysis['score'];
370370
return $analysis;
371371
}elseif ( $this->cache === true && ( $this->wordlist !== NULL || $this->wordlist !== '' ) ){
372-
$data = file_get_contents(dirname(__FILE__) . '/' . $dictionary);
372+
$data = @file_get_contents($dictionary);
373373
if ( $data === false ){
374374
throw new \Exception('Dictionary file was not found.');
375375
}
@@ -498,7 +498,7 @@ public function loadDictionaryCache(): bool{
498498
if ( $this->cache === false || $this->dictionary === NULL ){
499499
return false;
500500
}
501-
$data = @file_get_contents(dirname(__FILE__) . '/' . $this->dictionary);
501+
$data = @file_get_contents($this->dictionary);
502502
if ( $data === false ){
503503
throw new \Exception('Unable to load the dictionary.');
504504
}
@@ -640,7 +640,7 @@ public function generateHumanReadable(int $length, int $numLength = NULL): strin
640640
}
641641
return Hash::generateRandomNumber(0, 1) === 1 ? $password . $number : $number . $password;
642642
}
643-
$data = file_get_contents(dirname(__FILE__) . '/' . $dictionary);
643+
$data = @file_get_contents($dictionary);
644644
if ( $data === false ){
645645
throw new \Exception('Unable to read data from dictionary file.');
646646
}
@@ -924,8 +924,8 @@ public static function compareSimpleHash(string $password, string $hash, string
924924
/**
925925
* Checks if a given password corresponds with the given hash as associative array.
926926
*
927-
* @param string password A string containing the password.
928-
* @param array hash An associative array containing the password hash and the respective parameters.
927+
* @param string $password A string containing the password.
928+
* @param array $hash An associative array containing the password hash and the respective parameters.
929929
*
930930
* @return bool If the given password corresponds will be returned "true", otherwise "false".
931931
*

0 commit comments

Comments
 (0)