mee2nce408 has asked for the wisdom of the Perl Monks concerning the following question:

I wanted to know if it was possible to use DBI to change the password of a database user to something static (something declared in the code). I have to write a script that changes the password of a database user. There are multiple databases so it would be time consuming to log into each database and change the password one by one. Thanks for any help. Wes

Replies are listed 'Best First'.
Re: Can you use DBI to do this?
by cfreak (Chaplain) on Jul 11, 2003 at 21:29 UTC

    User and passwords for databases are probably going to be database specific, so if you database allows you to change them through an SQL query then you can do it through DBI. Even then the queries may be different between databases.

    Bottom line if your database supports it and you're not worried about portability, then yes. Though I wouldn't recommend it.

    Lobster Aliens Are attacking the world!
Re: Can you use DBI to do this?
by dws (Chancellor) on Jul 11, 2003 at 22:23 UTC
    I wanted to know if it was possible to use DBI to change the password of a database user to something static ...

    Details for changing passwords vary by vendor. Assuming you're using MySQL,

    UPDATE user SET Password=password(?) WHERE User = ?
    will do the trick, assuming that
    • you're in the mysql database,
    • you have privs to update the Password field in the user table,
    • you plug in a password and a username at execute() time, and
    • the username you plug in matches one that exists in the database.

    Just prepare and execute the query as you would any other query through DBI.

      You can set your password in MySQL without any special privileges.

      See the MySQL manual

      SET PASSWORD = PASSWORD('some password')

      Set the password for the current user. Any non-anonymous user can change his own password!

      No need to call flush privileges either

      Also, you need to be able to flush privileges as the password wouldn't change until the database itself is restarted.

      flush privileges

      Just mentioning this to head off a VERY annoying feature. Hope this helps.

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1