Added tabs in function

This commit is contained in:
Frank Bischof 2023-04-07 08:50:38 +02:00
parent 35f2baf3a8
commit b0b1946be8

View File

@ -1,13 +1,12 @@
<?php <?php
function password_check($password_check_input) { function password_check($password_check_input) {
// Encrypt your password and uppercase all chars
$sha1_password = strtoupper(sha1($password_check_input));
// Trim to the first 5 characters of the hash
$sha1_password_short = substr($sha1_password, 0, 5);
// Encrypt your password and uppercase all chars // Fetch hash list
$sha1_password = strtoupper(sha1($password_check_input)); $curl = curl_init();
// Trim to the first 5 characters of the hash
$sha1_password_short = substr($sha1_password, 0, 5);
// Fetch hash list
$curl = curl_init();
curl_setopt_array($curl, array( curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.pwnedpasswords.com/range/$sha1_password_short", CURLOPT_URL => "https://api.pwnedpasswords.com/range/$sha1_password_short",
@ -22,17 +21,17 @@ $curl = curl_init();
), ),
)); ));
$response = curl_exec($curl); $response = curl_exec($curl);
$err = curl_error($curl); $err = curl_error($curl);
// Put reponse into an array // Put reponse into an array
$lines = explode(PHP_EOL, $response); $lines = explode(PHP_EOL, $response);
// Set hitcounter to ZERO // Set hitcounter to ZERO
$hitcounter=0; $hitcounter=0;
// Loop through all lines // Loop through all lines
foreach ($lines as $line => $row) { foreach ($lines as $line => $row) {
// Join the 5 sha1 chars with the result // Join the 5 sha1 chars with the result
$row = $sha1_password_short . $row; $row = $sha1_password_short . $row;
// Break output // Break output
@ -44,19 +43,19 @@ foreach ($lines as $line => $row) {
if ($row == $sha1_password) { if ($row == $sha1_password) {
$hitcounter++; $hitcounter++;
} }
} }
curl_close($curl); curl_close($curl);
if ($err) { if ($err) {
echo "cURL Error: $err"; echo "cURL Error: $err";
} }
if ($hitcounter != 0) { if ($hitcounter != 0) {
echo "<p><center>The chosen password is known as a breached password!<br> echo "<p><center>The chosen password is known as a breached password!<br>
Please select a different password</center></p>"; Please select a different password</center></p>";
die; die;
} }
} }
password_check("MySsecretPassword"); password_check("MySsecretPassword");