-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use password policy functions from ltb-common (#968)
- use check_password_strength and checkEntropyJSON from ltb-common - externalize ppolicy smarty assignments into a dedicated function
- Loading branch information
David Coutadeur
committed
Sep 9, 2024
1 parent
d5cace9
commit fc28f72
Showing
9 changed files
with
49 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,15 @@ | ||
<?php | ||
|
||
/* | ||
Pre-requisites: install zxcvbn library | ||
Make sure to have this in composer.json: | ||
"require": { | ||
"bjeavons/zxcvbn-php": "^1.0" | ||
} | ||
and run: composer update | ||
*/ | ||
|
||
require_once '../vendor/autoload.php'; | ||
use ZxcvbnPhp\Zxcvbn; | ||
|
||
|
||
try{ | ||
$zxcvbn = new Zxcvbn(); | ||
error_log("Module Zxcvbn successfully loaded"); | ||
} | ||
catch(Throwable $e){ | ||
error_log("Could not load Zxcvbn module: ".$e); | ||
exit(1); | ||
} | ||
|
||
/* Check user password against zxcvbn library | ||
Input : new user base64-encoded password | ||
Output: JSON response: { "level" => int, "message" => "msg" } */ | ||
|
||
function checkEntropyJSON($password_base64) | ||
{ | ||
$response_params = array(); | ||
$zxcvbn = new Zxcvbn(); | ||
|
||
if( ! isset($password_base64) || empty($password_base64)) | ||
{ | ||
error_log("checkEntropy: missing parameter password"); | ||
$response_params["level"] = -1; | ||
$response_params["message"] = "missing parameter password"; | ||
print json_encode($response_params); | ||
exit(1); | ||
} | ||
|
||
$p = base64_decode($password_base64); | ||
// force encoding to utf8, as iso-8859-1 is not supported by zxcvbn | ||
$password = mb_convert_encoding($p, 'UTF-8', 'ISO-8859-1'); | ||
error_log("checkEntropy: password taken from submitted form"); | ||
|
||
$entropy = $zxcvbn->passwordStrength("$password"); | ||
|
||
$response_params["level"] = strval($entropy["score"]); | ||
$response_params["message"] = $entropy['feedback']['warning'] ? strval($entropy['feedback']['warning']) : ""; | ||
|
||
error_log("checkEntropy: level " . $response_params["level"] . " msg: " . $response_params["message"]); | ||
|
||
print json_encode($response_params); | ||
exit(0); | ||
} | ||
|
||
// new password sent in the url, base64 encoded | ||
$newpass = htmlspecialchars($_POST["password"]); | ||
checkEntropyJSON($newpass); | ||
$entropy_response = \Ltb\Password::checkEntropyJSON($newpass); | ||
if ($debug) { | ||
error_log("checkEntropy: ".$entropy_response); | ||
} | ||
|
||
print $entropy_response; | ||
exit(0); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.