Brian's Waste of Time

Fri, 20 Feb 2004

Better GroovySQL Example

Glen complained that the example in my previous post was pretty bad, so here is a better one in honor of Andy ;-)

<step name="md5-passwords" type="groovy">
    <script>
import groovy.sql.Sql
import java.security.MessageDigest

sql = new Sql(connection)

sql.queryEach("select password, user_id from users") {
    MessageDigest md = MessageDigest.getInstance("MD5")
    sql.execute("update users set password=? where user_id=?",
                 [md.digest(it.password.bytes), it.user_id])
}
    </script>
</step>

=)

writebacks...

Brett Morgan


Any particular need to create the MessageDigest inside the loop? md.reset() would be a lot quicker ;-)

Brian McCallister

md.reset
Much appreciated! In a real case I would also salt the password with the user_id and base64 encode it, but... this is an example before goign to bed ;-)

Andy

http://jboss.org
Umm, you're still breaking microsoft patent right?

Glen Stampoultzis


Much better - thanks! Now all I need is a migration tool that will do cross database schema migration for my hibernate databases.

comment...

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Spam Guard, translate l33t to English: (hint, it's an Australian animal, plural form)
Comments:
Save my Name and URL/Email for next time