File: migrate_to_md5.php3

package info (click to toggle)
phplib 2%3A7.2d-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,612 kB
  • ctags: 198
  • sloc: php: 6,095; pascal: 186; perl: 95; makefile: 78; sh: 6
file content (54 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<? 
# Script to migrate from regular authentication to md5-hashed passwords
#
# Jim Zajkowski <jim@jimz.com>
#
# This only works for MySQL, since I don't have any other database.  
# You'll need to change it as necessary.

# Before running this script you must create the auth_user_md5 table.  
# Check out create_auth_md5.mysql, which is the proper SQL to create
# the table.

# Please set up DB_Example (or a subclass) in the php/local.inc file
# first, as I depend on it.  Configure for your site:

$database_class  = "DB_Example";       ## Class for login credentials
$from_table      = "auth_user";        ## Table with current users
$to_table        = "auth_user_md5";    ## New table to make
$clear_to_first  = 1;                  ## Delete auth table first

#####################################################################

$db = new $database_class;
$db2 = new $database_class;

if ($clear_to_first) {
   $db->query(sprintf("delete from %s", $to_table));
}

echo "Converting $from_table to $to_table...<br>";

$db->query(sprintf("select user_id, username, perms, password from %s",
                     $from_table)
          );

while($db->next_record()) {
   $uid  = $db->f("user_id");
   $user = $db->f("username");
   $perm = $db->f("perms");
   $pass = $db->f("password");
   
   $newpass = md5($pass);

   $db2->query(sprintf("insert into %s (user_id, username, perms, password)" .
		         "values ('%s', '%s', '%s', '%s')", 
	                 $to_table, $uid, $user, $perm, $newpass));

   echo "Converted $user...<br>";
}

echo "Conversion complete.<br>";

?>