svn-gvsig-desktop / tags / v1_1_Build_1000 / install / IzPack / sample / src / PWDEncryptor.java @ 31466
History | View | Annotate | Download (2.92 KB)
1 | 5819 | cesar | /*
|
---|---|---|---|
2 | * $Id$
|
||
3 | * Copyright (C) 2003 Elmar Grom
|
||
4 | *
|
||
5 | * File : PWDEncryptor.java
|
||
6 | * Description : Example code for a password encryption service
|
||
7 | * Author's email : elmar@grom.net
|
||
8 | * Author's Website : http://www.izforge.com
|
||
9 | *
|
||
10 | * This program is free software; you can redistribute it and/or
|
||
11 | * modify it under the terms of the GNU General Public License
|
||
12 | * as published by the Free Software Foundation; either version 2
|
||
13 | * of the License, or any later version.
|
||
14 | *
|
||
15 | * This program is distributed in the hope that it will be useful,
|
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
18 | * GNU General Public License for more details.
|
||
19 | *
|
||
20 | * You should have received a copy of the GNU General Public License
|
||
21 | * along with this program; if not, write to the Free Software
|
||
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
23 | */
|
||
24 | |||
25 | package com.izforge.izpack.sample; |
||
26 | |||
27 | import com.izforge.izpack.panels.*; |
||
28 | |||
29 | /*---------------------------------------------------------------------------*/
|
||
30 | /**
|
||
31 | * This class provides a demonstration for using an encryption service in
|
||
32 | * connection with a password field, as used in a <code>UserInputPanel</code>.
|
||
33 | *
|
||
34 | * @version 0.0.1 / 02/19/03
|
||
35 | * @author Elmar Grom
|
||
36 | */
|
||
37 | /*---------------------------------------------------------------------------*/
|
||
38 | public class PWDEncryptor implements Processor |
||
39 | { |
||
40 | /*--------------------------------------------------------------------------*/
|
||
41 | /**
|
||
42 | * Encrypts the a password and returns the encrypted result. <br>
|
||
43 | * <b>Note:</b> this is not a real encryption algorithm. The code only
|
||
44 | * demonstrates the use of this interface in a real installation environment.
|
||
45 | * For a real application a proper encryption mechanism must be used. Though
|
||
46 | * Java 1.4.X provides such algorithms, you need to consider that not all
|
||
47 | * potential target environments have this version installed. It seems best
|
||
48 | * to include the necessary encryption library with the installer.
|
||
49 | *
|
||
50 | * @param client the client object using the services of this encryptor.
|
||
51 | *
|
||
52 | * @return the encryption result.
|
||
53 | */
|
||
54 | /*--------------------------------------------------------------------------*/
|
||
55 | public String process (ProcessingClient client) |
||
56 | { |
||
57 | if (client.getNumFields () < 1) |
||
58 | { |
||
59 | return (""); |
||
60 | } |
||
61 | |||
62 | char [] password = client.getFieldContents (0).toCharArray (); |
||
63 | char [] result = new char [password.length]; |
||
64 | int temp;
|
||
65 | |||
66 | for (int i = 0; i < password.length; i++) |
||
67 | { |
||
68 | temp = password [i] - 57;
|
||
69 | if (i > 0) |
||
70 | { |
||
71 | temp = temp + password [i - 1];
|
||
72 | } |
||
73 | |||
74 | if ((temp % 3) == 0) |
||
75 | { |
||
76 | temp = temp + 13;
|
||
77 | } |
||
78 | if (temp < 0) |
||
79 | { |
||
80 | temp = temp + 193;
|
||
81 | } |
||
82 | |||
83 | result [i] = (char)temp;
|
||
84 | } |
||
85 | |||
86 | return (new String (result)); |
||
87 | } |
||
88 | } |
||
89 | /*---------------------------------------------------------------------------*/ |