/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.iface;

import com.silverwrist.dynamo.except.AuthenticationException;

/**
 * The public intrface implemented by all Dynamo <EM>authenticators</EM>.  An <EM>authenticator</EM> is a piece of
 * code that handles two tasks:
 * <OL>
 *   <LI>The transformation of private authentication data into a format suitable for storing in the database.</LI>
 *   <LI>The comparison of that private data to private data obtained from the user, and returning whether or not
 *     it matches.</LI>
 * </OL>
 * For example, in the {@link com.silverwrist.dynamo.db.DefaultHashAuthenticator DefaultHashAuthenticator}, the
 * former task consists of taking a password and processing it through a secure one-way hash function to produce a
 * string which may be stored in the database, and the latter task consists of applying the same function to a user-
 * supplied password and comparing the resulting hash value against the one retrieved from the database.
 *
 * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
 * @version X
 */
public interface Authenticator
{
  /**
   * Given a piece of stored authentication data (which has been transformed with
   * {@link #processInputData(java.lang.String) processInputData()}) and a piece of user-supplied authentication
   * data (which has not), returns whether or not they match.
   *
   * @param stored_data The stored authentication data from the database.
   * @param input_data The input authentication data from the user,
   * @return <CODE>true</CODE> if the two pieces of data match, <CODE>false</CODE> if not.
   * @exception com.silverwrist.dynamo.except.AuthenticationException If there was a problem with the authenticator.
   */
  public boolean authenticate(String stored_data, String input_data) throws AuthenticationException;

  /**
   * Transforms a piece of input data, such as a password, into a format suitable for storing in the database.
   *
   * @param input_data Input data to be transformed.
   * @return The transformed input data.
   * @exception com.silverwrist.dynamo.except.AuthenticationException If there was a problem with the authenticator.
   */
  public String processInputData(String input_data) throws AuthenticationException;

} // end interface Authenticator
