KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > PasswordHasher


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.test;
8
9 import org.jboss.security.Util;
10
11 /** A utility program for generating password hashes given the hashAlgorithm,
12 hashEncoding, and hashCharset options used by the UsernamePasswordLoginModule.
13 The command line usage is:
14 PasswordHasher [hashAlgorithm [hashEncoding [hashCharset]]] password
15
16  @author Scott.Stark@jboss.org
17  @version $Revision: 1.2.26.1 $
18  */

19 public class PasswordHasher
20 {
21    static String JavaDoc usage = "Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password";
22
23    /** @param args the command line arguments
24     *Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password
25     */

26    public static void main(String JavaDoc[] args)
27    {
28       String JavaDoc hashAlgorithm = "MD5";
29       String JavaDoc hashEncoding = "base64";
30       String JavaDoc hashCharset = null;
31       String JavaDoc password = null;
32       if( args.length == 0 || args[0].startsWith("-h") )
33          throw new IllegalStateException JavaDoc(usage);
34       switch( args.length )
35       {
36          case 4:
37             hashAlgorithm = args[0];
38             hashEncoding = args[1];
39             hashCharset = args[2];
40             password = args[3];
41          break;
42          case 3:
43             hashAlgorithm = args[0];
44             hashEncoding = args[1];
45             password = args[2];
46          break;
47          case 2:
48             hashAlgorithm = args[0];
49             password = args[1];
50          break;
51          case 1:
52             password = args[0];
53          break;
54       }
55       String JavaDoc passwordHash = Util.createPasswordHash(hashAlgorithm, hashEncoding,
56          hashCharset, null, password);
57       System.out.println("passwordHash = "+passwordHash);
58    }
59
60 }
61
Popular Tags