By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

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

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1.  UPDATE users SET Password = 
Dec 23 '10 #1
Share this Question
Share on Google+
6 Replies


AutumnsDecay
100+
P: 170
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.

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM users";
  2. $result = mysql_result($query);
  3.  
  4. while ($row = mysql_fetch_assoc($result)){
  5.     $username = $row['username'];
  6.     $password = $row['password'];
  7.  
  8.     $newpassword = crypt($password);
  9.  
  10.     $query2 = "UPDATE users WHERE username = '$username' AND password = '$password' SET password = '$newpassword'";
  11.  
  12.     mysql_query($query2);
  13. }
  14.  
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.
Dec 23 '10 #2

Rabbit
Expert Mod 10K+
P: 12,366
Crypt(password) doesn't work?
Dec 24 '10 #3

AutumnsDecay
100+
P: 170
Again, I have never used PERL, I would assume crypt would work the same way as PHPs md5 function. I could be wrong.
Dec 24 '10 #4

Rabbit
Expert Mod 10K+
P: 12,366
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).
Dec 24 '10 #5

P: 2
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.crypt does not exist
Dec 28 '10 #6

Rabbit
Expert Mod 10K+
P: 12,366
I think you have to use encrypt. I believe it's a wrapper for crypt.
Dec 28 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.