I just made a script to do just what you need. It changes all passwords in the database to randomly generated passwords. Yes, I did take the encrypt() function directly from L2CP.
NOTE: Someone else should check my work before it's used.
passgen.php
PHP Code:
<?php
include 'config.php';
function opensql() {
$dbhandle = mssql_connect ($_dbhost, $_dbuser, $_dbpass);
mssql_select_db ("lin2db", $dbhandle) or die(mysql_error());
}
function closesql() {
mssql_close($dbhandle);
}
function encrypt($str) {
$key = array();
$dst = array();
$i = 0;
$nBytes = strlen($str);
while ($i < $nBytes){
$i++;
$key[$i] = ord(substr($str, $i - 1, 1));
$dst[$i] = $key[$i];
}
$rslt = $key[1] + $key[2]*256 + $key[3]*65536 + $key[4]*16777216;
$one = $rslt * 213119 + 2529077;
$one = $one - intval($one/ 4294967296) * 4294967296;
$rslt = $key[5] + $key[6]*256 + $key[7]*65536 + $key[8]*16777216;
$two = $rslt * 213247 + 2529089;
$two = $two - intval($two/ 4294967296) * 4294967296;
$rslt = $key[9] + $key[10]*256 + $key[11]*65536 + $key[12]*16777216;
$three = $rslt * 213203 + 2529589;
$three = $three - intval($three/ 4294967296) * 4294967296;
$rslt = $key[13] + $key[14]*256 + $key[15]*65536 + $key[16]*16777216;
$four = $rslt * 213821 + 2529997;
$four = $four - intval($four/ 4294967296) * 4294967296;
$key[4] = intval($one/16777216);
$key[3] = intval(($one - $key[4] * 16777216) / 65535);
$key[2] = intval(($one - $key[4] * 16777216 - $key[3] * 65536) / 256);
$key[1] = intval(($one - $key[4] * 16777216 - $key[3] * 65536 - $key[2] * 256));
$key[8] = intval($two/16777216);
$key[7] = intval(($two - $key[8] * 16777216) / 65535);
$key[6] = intval(($two - $key[8] * 16777216 - $key[7] * 65536) / 256);
$key[5] = intval(($two - $key[8] * 16777216 - $key[7] * 65536 - $key[6] * 256));
$key[12] = intval($three/16777216);
$key[11] = intval(($three - $key[12] * 16777216) / 65535);
$key[10] = intval(($three - $key[12] * 16777216 - $key[11] * 65536) / 256);
$key[9] = intval(($three - $key[12] * 16777216 - $key[11] * 65536 - $key[10] * 256));
$key[16] = intval($four/16777216);
$key[15] = intval(($four - $key[16] * 16777216) / 65535);
$key[14] = intval(($four - $key[16] * 16777216 - $key[15] * 65536) / 256);
$key[13] = intval(($four - $key[16] * 16777216 - $key[15] * 65536 - $key[14] * 256));
$dst[1] = $dst[1] ^ $key[1];
$i=1;
while ($i<16){
$i++;
$dst[$i] = $dst[$i] ^ $dst[$i-1] ^ $key[$i];
}
$i=0;
while ($i<16){
$i++;
if ($dst[$i] == 0) {
$dst[$i] = 102;
}
}
$encrypt = "0x";
$i=0;
while ($i<16){
$i++;
if ($dst[$i] < 16) {
$encrypt = $encrypt . "0" . dechex($dst[$i]);
} else {
$encrypt = $encrypt . dechex($dst[$i]);
}
}
return $encrypt;
}
function random_password($length) {
srand();
$rand_pass = "";
for($i=1;$i<=$length;$i++) {
$rnd = rand(1,26);
switch ($rnd) {
case 1:
$upper = rand(0,1);
if ($upper==1)
$char = 'A';
else
$char = 'a';
break;
case 2:
$upper = rand(0,1);
if ($upper==1)
$char = 'B';
else
$char = 'b';
break;
case 3:
$upper = rand(0,1);
if ($upper==1)
$char = 'C';
else
$char = 'c';
break;
case 4:
$upper = rand(0,1);
if ($upper==1)
$char = 'D';
else
$char = 'd';
break;
case 5:
$upper = rand(0,1);
if ($upper==1)
$char = 'E';
else
$char = 'e';
break;
case 6:
$upper = rand(0,1);
if ($upper==1)
$char = 'F';
else
$char = 'f';
break;
case 7:
$upper = rand(0,1);
if ($upper==1)
$char = 'G';
else
$char = 'g';
break;
case 8:
$upper = rand(0,1);
if ($upper==1)
$char = 'H';
else
$char = 'h';
break;
case 9:
$upper = rand(0,1);
if ($upper==1)
$char = 'I';
else
$char = 'i';
break;
case 10:
$upper = rand(0,1);
if ($upper==1)
$char = 'J';
else
$char = 'j';
break;
case 11:
$upper = rand(0,1);
if ($upper==1)
$char = 'K';
else
$char = 'k';
break;
case 12:
$upper = rand(0,1);
if ($upper==1)
$char = 'L';
else
$char = 'l';
break;
case 13:
$upper = rand(0,1);
if ($upper==1)
$char = 'M';
else
$char = 'm';
break;
case 14:
$upper = rand(0,1);
if ($upper==1)
$char = 'N';
else
$char = 'n';
break;
case 15:
$upper = rand(0,1);
if ($upper==1)
$char = 'O';
else
$char = 'o';
break;
case 16:
$upper = rand(0,1);
if ($upper==1)
$char = 'P';
else
$char = 'p';
break;
case 17:
$upper = rand(0,1);
if ($upper==1)
$char = 'Q';
else
$char = 'q';
break;
case 18:
$upper = rand(0,1);
if ($upper==1)
$char = 'R';
else
$char = 'r';
break;
case 19:
$upper = rand(0,1);
if ($upper==1)
$char = 'S';
else
$char = 's';
break;
case 20:
$upper = rand(0,1);
if ($upper==1)
$char = 'T';
else
$char = 't';
break;
case 21:
$upper = rand(0,1);
if ($upper==1)
$char = 'U';
else
$char = 'u';
break;
case 22:
$upper = rand(0,1);
if ($upper==1)
$char = 'V';
else
$char = 'v';
break;
case 23:
$upper = rand(0,1);
if ($upper==1)
$char = 'W';
else
$char = 'w';
break;
case 24:
$upper = rand(0,1);
if ($upper==1)
$char = 'X';
else
$char = 'x';
break;
case 25:
$upper = rand(0,1);
if ($upper==1)
$char = 'Y';
else
$char = 'y';
break;
case 26:
$upper = rand(0,1);
if ($upper==1)
$char = 'Z';
else
$char = 'z';
break;
case 27:
$char = 1;
break;
case 28:
$char = 2;
break;
case 29:
$char = 3;
break;
case 30:
$char = 4;
break;
case 31:
$char = 5;
break;
case 32:
$char = 6;
break;
case 33:
$char = 7;
break;
case 34:
$char = 8;
break;
case 35:
$char = 9;
break;
case 36:
$char = 0;
break;
}
$rand_pass .= $char;
}
return $rand_pass;
}
$query1 = "SELECT name, email FROM [ssn]";
opensql();
$ssn_data = mssql_query($query1);
closesql();
while($row = mssql_fetch_array($ssn_data)) {
$account = $row['name'];
$email = $row['email'];
$new_pword = random_password($_new_passlength);
$encrypt_pword = encrypt($new_pword);
$query2 = "UPDATE user_auth SET password = $encrypt_pword WHERE account = '$account'";
opensql();
$auth_data = mssql_query($query2);
closesql();
include "./phpmailer/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = $_smtp_host;
$mail->SMTPAuth = true;
$mail->Username = $_smtp_user;
$mail->Password = $_smtp_pass;
$mail->From = $_from_email_address;
$mail->FromName = $_from_name;
$mail->AddAddress($email,$account);
$mail->Subject = $_server_name . " -- Password Change (URGENT)";
$mail->Body = "This is an automated message:\n\n";
$mail->Body .= "All passwords for our server have been changed to random passwords.\n";
$mail->Body .= "Your new login information is:\n\n";
$mail->Body .= " Username: {$account}\n";
$mail->Body .= " Password: {$new_pword}\n\n";
$mail->Body .= "Thanks,\n";
$mail->Body .= "The {$_server_name} Staff";
$mail->Send();
}
?>
config.php
PHP Code:
<?php
$_dbhost = "localhost"; // Host: SQL server
$_dbuser = ""; // Username: SQL server
$_dbpass = ""; // Password: SQL server
$_server_name = "Lineage II"; // Name of your server
$_from_name = "Lineage II"; // Name shown as the 'sender'
$_from_email_address = "[email protected]"; // Return address
$_smtp_host = "localhost"; // Hostname: SMTP server
$_smtp_pass = ""; // Password: SMTP server
$_smtp_user = ""; // Username: SMTP server
$_new_passlength = 8; // Length: of the random password
?>