[jboss-user] [JBoss Seam] - How to decode hash password?
LockDog
do-not-reply at jboss.com
Wed Oct 17 13:22:51 EDT 2007
Seamspace example:
package org.teamdev.librarian.user;
|
| import org.apache.commons.codec.binary.Hex;
| import org.jboss.seam.Component;
| import org.jboss.seam.annotations.Name;
|
| import java.security.MessageDigest;
|
| @Name("hash")
| public class Hash {
| String hashFunction = "MD5";
| String charset = "UTF-8";
|
| public String hash(String password) {
| try {
| MessageDigest md = MessageDigest.getInstance(hashFunction);
| md.update(password.getBytes(charset));
| byte[] raw = md.digest();
| return new String(Hex.encodeHex(raw));
| }
| catch (Exception e) {
| throw new RuntimeException(e);
| }
| }
|
| public String getCharset() {
| return charset;
| }
|
| public void setCharset(String charset) {
| this.charset = charset;
| }
|
| public String getHashFunction() {
| return hashFunction;
| }
|
| public void setHashFunction(String hashFunction) {
| this.hashFunction = hashFunction;
| }
|
| public static Hash instance() {
| return (Hash) Component.getInstance(Hash.class);
| }
| }
How to decode (unhash) password?
public String unHash(String hashedPassword) {
| try {
| MessageDigest md = MessageDigest.getInstance(hashFunction);
| md.update(hashedPassword.getBytes(charset));
| char[] raw = md.digest().toString().toCharArray();
| return new String(Hex.decodeHex(raw));
| }
| catch (Exception e) {
| throw new RuntimeException(e);
| }
| }
Don't work =(
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096212#4096212
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096212
More information about the jboss-user
mailing list