001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2003 Elmar Grom
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package   com.izforge.izpack.sample;
023
024import com.izforge.izpack.panels.ProcessingClient;
025import com.izforge.izpack.panels.Processor;
026
027/*---------------------------------------------------------------------------*/
028/**
029 * This class provides a demonstration for using an encryption service in
030 * connection with a password field, as used in a <code>UserInputPanel</code>.
031 *
032 * @version  0.0.1 / 02/19/03
033 * @author   Elmar Grom
034 */
035/*---------------------------------------------------------------------------*/
036public class PWDEncryptor implements Processor
037{
038 /*--------------------------------------------------------------------------*/
039 /**
040  * Encrypts the a password and returns the encrypted result. <br>
041  * <b>Note:</b> this is not a real encryption algorithm. The code only
042  * demonstrates the use of this interface in a real installation environment.
043  * For a real application a proper encryption mechanism must be used. Though
044  * Java 1.4.X provides such algorithms, you need to consider that not all
045  * potential target environments have this version installed. It seems best
046  * to include the necessary encryption library with the installer.
047  *
048  * @param     client   the client object using the services of this encryptor.
049  *
050  * @return    the encryption result.
051  */
052 /*--------------------------------------------------------------------------*/
053  public String process (ProcessingClient client)
054  {
055    if (client.getNumFields () < 1)
056    {
057      return ("");
058    }
059    
060    char [] password = client.getFieldContents (0).toCharArray ();
061    char [] result   = new char [password.length];
062    int  temp;
063    
064    for (int i = 0; i < password.length; i++)
065    {
066      temp = password [i] - 57;
067      if (i > 0)
068      {
069        temp = temp + password [i - 1];
070      }
071
072      if ((temp % 3) == 0)
073      {
074        temp = temp + 13;
075      }
076      if (temp < 0)
077      {
078        temp = temp + 193;
079      }
080    
081      result [i] = (char)temp;
082    }
083
084    return (new String (result));
085  }
086}
087/*---------------------------------------------------------------------------*/