users@glassfish.java.net

Glassfish Security - jdbcRealm: How to configure login with SHA-256 digest

From: <glassfish_at_javadesktop.org>
Date: Mon, 09 Aug 2010 15:02:18 PDT

I use jdbcRealm for security in my glassfish v3.0.1 b22. It is set up so that it use the USER table inside my database for authentication by following this blog: http://blogs.sun.com/foo/entry/mort_learns_jdbc_realm_authentication. I got it working fine, if I leave the digest algorithm as plain text. However when i try to use SHA-256 for digest algorithm, it stop working.
What I did is specify in Glassfish - Security - Realm - jdbcRealm - digest that I want SHA-256 (I just type SHA-256 inside digest field). Then I wrote a simple java program to convert password text into SHA-256 hash. I then paste that hash inside my password field in the database. btw, password field is type varchar(30). I cant log in anymore. One thing I notice that my simple java program generated different hash every time for the same text field. So please help. Below are my simple java program

[code]
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            String text = "admin";
            md.update(text.getBytes("UTF-8"));
            byte[] digest = md.digest();
            System.out.println(digest.toString());
[/code]
[Message sent by forum member 'kingdomheart']

http://forums.java.net/jive/thread.jspa?messageID=479732