Update a MYSQL db password using crypt() technology on MYSQL connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Rose
    New Member
    • Dec 2010
    • 2

    Update a MYSQL db password using crypt() technology on MYSQL connection

    Update a MYSQL db password using crypt() technology on MYSQL connection.

    I am looking to update a user table of passwords that were inserted without using crypt() on a Perl development project. I am using MYSQL to connect to the database and I need to update the passwords to be encrypted using the same method as the website process. How do I update?

    I got this far:

    Code:
     UPDATE users SET Password =
  • AutumnsDecay
    New Member
    • Mar 2008
    • 170

    #2
    You could do a WHILE loop for it. I don't know PERL, so this will be the PHP equivalent. I doubt they're very different for this type of thing.

    Code:
    $query = "SELECT * FROM users";
    $result = mysql_result($query);
    
    while ($row = mysql_fetch_assoc($result)){
        $username = $row['username'];
        $password = $row['password'];
    
        $newpassword = crypt($password);
    
        $query2 = "UPDATE users WHERE username = '$username' AND password = '$password' SET password = '$newpassword'";
    
        mysql_query($query2);
    }
    This would work in PHP, I believe, so it shouldn't be too much work to transpose it to PERL, but again, I've never used PERL.

    You may or may not run into issues trying to use crypt() on an already crypted password.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Crypt(password) doesn't work?

      Comment

      • AutumnsDecay
        New Member
        • Mar 2008
        • 170

        #4
        Again, I have never used PERL, I would assume crypt would work the same way as PHPs md5 function. I could be wrong.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          I don't think he's trying to use PERL to do the update. I think he's trying to do the update on the backend which means he just needs to run the SQL: update table set password = crypt(password) .

          Comment

          • Matt Rose
            New Member
            • Dec 2010
            • 2

            #6
            I am using Windows XP, connecting using Navicat to my database (MySQL) which is hosted on cpanel. My website was written using Perl. I have inserted the usernames and passwords into the table, though the "encryption " that is being used is 'unix crypt()' When I go to update it through the Navicat interface this is the error.
            [SQL] update users set password = crypt('password ')

            [Err] 1305 - FUNCTION databasename.cr ypt does not exist

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              I think you have to use encrypt. I believe it's a wrapper for crypt.

              Comment

              Working...