Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 11.10.2006, 16:11   #1
Shaker
Архивный участник
 
Join Date: Oct 2006
Posts: 24
Default [REQUEST] PHP Script

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.
Shaker is offline  
Old 11.10.2006, 16:24   #2
scrap512
Архивный участник
 
Join Date: Jul 2006
Posts: 77
Default

do you got $$$? if so lets talk
scrap512 is offline  
Old 11.10.2006, 18:32   #3
Kengurius
Архивный участник
 
Join Date: Apr 2006
Posts: 54
Default

Quote:
Originally Posted by scrap512 View Post
do you got $$$? if so lets talk
If i would be Mod, i would ban u for such worlds..
Kengurius is offline  
Old 11.10.2006, 18:45   #4
Shaker
Архивный участник
 
Join Date: Oct 2006
Posts: 24
Default

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.
Shaker is offline  
Old 11.10.2006, 19:19   #5
Shawnmb
Архивный участник
 
Join Date: Feb 2005
Posts: 307
Default

Quote:
Originally Posted by Kengurius View Post
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).
Shawnmb is offline  
Old 12.10.2006, 01:43   #6
LORd_RiVE
Архивный участник
 
Join Date: Oct 2006
Posts: 4
Default

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.
LORd_RiVE is offline  
Old 12.10.2006, 02:20   #7
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

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
?>
poltomb is offline  
Old 12.10.2006, 02:26   #8
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

Quote:
Originally Posted by scrap512 View Post
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 is offline  
Old 12.10.2006, 02:41   #9
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

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 байт
poltomb is offline  
Old 12.10.2006, 09:36   #10
Shaker
Архивный участник
 
Join Date: Oct 2006
Posts: 24
Default

Thank You a lot guys. I reallly appreciate it.
Shaker is offline  
Old 12.10.2006, 10:27   #11
Stazis
Архивный участник
 
Join Date: Feb 2005
Posts: 200
Default

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.
Stazis is offline  
Old 13.10.2006, 00:01   #12
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

Maybe I could do that too...good idea. I gotta do my calculus homework first though :/
poltomb is offline  
Old 13.10.2006, 09:01   #13
Shaker
Архивный участник
 
Join Date: Oct 2006
Posts: 24
Default

Someone know PHP at enough stage to make script with this "Send me currently password" ?
Also how can i rest passwords in database?
Shaker is offline  
Old 13.10.2006, 17:18   #14
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

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..
poltomb is offline  
Old 13.10.2006, 17:21   #15
Shaker
Архивный участник
 
Join Date: Oct 2006
Posts: 24
Default

Yeah, that's good idea also..Someone could try to make it?
Shaker is offline  
Old 13.10.2006, 18:54   #16
Pole
Архивный участник
 
Join Date: Feb 2006
Posts: 10
Default

Quote:
Originally Posted by poltomb View Post
PHP Code:
$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 :

PHP Code:
$encrypt_pword = "";
while(
strlen($encrypt_pword)!=34){
   
$new_pword = random_password($_new_passlength);
   
$encrypt_pword = encrypt($new_pword);
} 
Pole is offline  
Old 13.10.2006, 20:59   #17
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

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.
poltomb is offline  
Old 13.10.2006, 21:05   #18
Pole
Архивный участник
 
Join Date: Feb 2006
Posts: 10
Default

Quote:
Originally Posted by poltomb View Post
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 ?

PHP Code:
$_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");
  }
} 
Pole is offline  
Old 13.10.2006, 22:43   #19
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

i see what you mean...hmmm methinks ill need to look for a new function...
poltomb is offline  
Old 16.10.2006, 15:41   #20
poltomb
Архивный участник
 
Join Date: Sep 2006
Posts: 81
Default

Quote:
Originally Posted by Pole View Post
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 :

PHP Code:
$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?
poltomb is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 20:10.