PDA

View Full Version : [REQUEST] PHP Script


Shaker
11.10.2006, 16:11
Hey,

I need to generate new passwords in whole database, so i need also to send them to account owners. Doing it manually would take years...

I'm lookin for script which would read passwords from MSSQL database and send them at e-mails which people used while registering..I don't have enough experience to make one...


Thank you for any help.

scrap512
11.10.2006, 16:24
do you got $$$? if so lets talk

Kengurius
11.10.2006, 18:32
do you got $$$? if so lets talk

If i would be Mod, i would ban u for such worlds..

Shaker
11.10.2006, 18:45
Well, i can understand that someone spent his time to write such script but maybe someone has it already written and could simply share it ...

It's a HELP section isn't it? Like for me it's a section made for people which looking for some advice provided by people which like to help others unselfishly, definitively you're not one of them.

Shawnmb
11.10.2006, 19:19
If i would be Mod, i would ban u for such worlds..

Selling server files and such is against the rules, there is (as far as I know) no rule against selling independant work outside of L2 files (such as PHP).

LORd_RiVE
12.10.2006, 01:43
i have a php script for that...
but it works like, the user go on the page, there he write his/her name in it, if its real then the script generate a new password fpr him/her and show it on the page..or send it in email...
Unfortunately, i don'th ave smtp server so could't test the email sender, but it have to work... if i have some time, i will post it soooooon.

poltomb
12.10.2006, 02:20
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
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
$_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
?>

poltomb
12.10.2006, 02:26
do you got $$$? if so lets talk
This wouldnt fit on the other post...(just under 10000 characters, lol):

You got to be kidding me, such an easy script to make and you were going to charge him for it. For shame. This is a *SHARING* community. I can understand if you spent many hours on a project, then wanting a little money. But for such a short project, no payment is necessary.

poltomb
12.10.2006, 02:41
If you do not have an smtp server, I have (somewhere) a free (legal) smtp server. Also, tomorrow, I will add the ability to change the SMTP port.

I am a forgetful person. You will need these files as well:

Вложения из исходного сообщения (сами файлы в копии отсутствуют):
phpmailer.zip — 55291 байт

Shaker
12.10.2006, 09:36
Thank You a lot guys. I reallly appreciate it.

Stazis
12.10.2006, 10:27
notice - think you will face to trouble sending so much letters per time - lot of ppl will not receive them for sure.
it is much better to reset all passwords and let users push "Send me password" button to spread letter sending for longer time.

poltomb
13.10.2006, 00:01
Maybe I could do that too...good idea. I gotta do my calculus homework first though :/

Shaker
13.10.2006, 09:01
Someone know PHP at enough stage to make script with this "Send me currently password" ?
Also how can i rest passwords in database?

poltomb
13.10.2006, 17:18
Sending current passwords would require a database containing all the current passwords...which is a secrity issue (which is also why the passwords are hashed in the first place). A send new password button would be a little more reasonable, and easier thing to do..

Shaker
13.10.2006, 17:21
Yeah, that's good idea also..Someone could try to make it?

Pole
13.10.2006, 18:54
$new_pword = random_password($_new_passlength);
$encrypt_pword = encrypt($new_pword);



If you use that, you will have some bugged encrypted password like :

0x0ffffff890ffffffcb0ffffffd40ffffffba0ffffff030ff ffffa00ffffffde0ffffffc60fffffff30ffffff6a0ffffff4 c0ffffff4c0ffffff810ffffff1b0ffffff3d0ffffff3d

and not :

0xb18e86b70a7a3ea99c052323ee745252

so i recommand to include the generation and encryption in a while till the lenght is ok :


$encrypt_pword = "";
while(strlen($encrypt_pword)!=34){
$new_pword = random_password($_new_passlength);
$encrypt_pword = encrypt($new_pword);
}

poltomb
13.10.2006, 20:59
well, I took that encrypt password method right out of L2CP (php). I'll check to be sure I copied and pasted the right code.

Pole
13.10.2006, 21:05
well, I took that encrypt password method right out of L2CP (php). I'll check to be sure I copied and pasted the right code.

yes, but the encrypt function of L2CP is bugged, wanna see ?


$_new_passlength = 8; // Length: of the random password
set_time_limit(900);
$i=1;
while($i<10000){
$i++;
$encrypt_pword = "";
$new_pword = random_password($_new_passlength);
$encrypt_pword = encrypt($new_pword);


if (strlen($encrypt_pword)!=34){
echo("$i\t$new_pword\t");
echo("$encrypt_pword\n");
}
}

poltomb
13.10.2006, 22:43
i see what you mean...hmmm methinks ill need to look for a new function...

poltomb
16.10.2006, 15:41
If you use that, you will have some bugged encrypted password like :

0x0ffffff890ffffffcb0ffffffd40ffffffba0ffffff030ff ffffa00ffffffde0ffffffc60fffffff30ffffff6a0ffffff4 c0ffffff4c0ffffff810ffffff1b0ffffff3d0ffffff3d

and not :

0xb18e86b70a7a3ea99c052323ee745252

so i recommand to include the generation and encryption in a while till the lenght is ok :


$encrypt_pword = "";
while(strlen($encrypt_pword)!=34){
$new_pword = random_password($_new_passlength);
$encrypt_pword = encrypt($new_pword);
}


I am wonderin if endianness is the problem with the encode function. On a windows box, the script works fine, but on a linux box, the output is similar to the one you have. Anyone got any suggestions?