Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function gen_password($seed, $username, $password_resets, $m = 2147483648, $count = 10) {
$results = [];
$x = $seed;
$a = crc32($username) % $m;
for ($i = 0; $i < $count; $i++) {
$x = ($a * $x + $password_resets) % $m;
$results[] = $x;
}
return $results;
}
print(gen_password(0, "test", 0))
<?php
if (function_exists('bcadd')) {
echo "BCMath is enabled\n";
} else {
echo "BCMath is NOT enabled\n";
}
function gen_password($seed, $username, $password_resets) {
$result = 0;
$x = $seed;
$a = crc32($username) % PHP_INT_MAX;
$password = '';
// Initialize LCG to password reset count
for ($i = 0; $i < $password_resets; $i++) {
$x = ($a * $x) % PHP_INT_MAX;
}
while (strlen($password) < 20) {
while ($result == 0) {
$x = bcmod(bcmul($a, $x), (string)PHP_INT_MAX);
$result = $x;
}
$charCode = ($result % 94) + 33;
// Divide twice to avoid giving the user consecutive LCG output
$result = intdiv(intdiv($result, 94), 94);
$password .= chr($charCode);
}
return $password;
}
print("not dead ");
$pw = gen_password(3, "admin", 0);
print(strlen($pw));
print(' ');
print($pw);