Mass MD5 encryption

Discussion in 'PHP' started by orlandolukas, Jun 9, 2008.

  1. #1
    i have a site and im upgrading it to a new script. but the password table needs to be updated with a mass md5 encryption. how would i go about doing this ?
     
    orlandolukas, Jun 9, 2008 IP
  2. Lucas3677

    Lucas3677 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    
    $query = mysql_query("SELECT * FROM `users` WHERE 1");
    
    while ($row = mysql_fetch_assoc($query))
    {
    	mysql_query("UPDATE `users` SET `password` = '" . md5($row['password']) . "' WHERE `ID_USER` = " . $row['ID_USER'] . " LIMIT 1");
    }
    
    echo "All done";
    
    ?>
    PHP:
    users -> user table
    password -> password column
    ID_USER -> the primary key

    I suggest you backup your table before you do this, just in case you accidentally run it 2 times and lose all the passwords.
     
    Lucas3677, Jun 9, 2008 IP
  3. Lucas3677

    Lucas3677 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I forgot to mention, you should connect to your database before, or it'll give errors.
     
    Lucas3677, Jun 9, 2008 IP
  4. orlandolukas

    orlandolukas Guest

    Messages:
    118
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok thanks alot
     
    orlandolukas, Jun 9, 2008 IP