1 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package org.acegisecurity.providers.encoding;
17
18 import org.springframework.dao.DataAccessException;
19
20
21 /**
22 * <p>
23 * Interface for performing authentication operations on a password.
24 * </p>
25 *
26 * @author colin sampaleanu
27 * @version $Id: PasswordEncoder.java 1784 2007-02-24 21:00:24Z luke_t $
28 */
29 public interface PasswordEncoder {
30 //~ Methods ========================================================================================================
31
32 /**
33 * <p>Encodes the specified raw password with an implementation specific algorithm.</p>
34 * <P>This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
35 * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
36 * plug in when the original password must be stored as-is.</p>
37 * <p>The specified salt will potentially be used by the implementation to "salt" the initial value before
38 * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
39 * This means that computation of digests for common dictionary words will be different than those in the backend
40 * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
41 * used (rather than a system-wide salt), it also means users with the same password will have different digest
42 * encoded passwords in the backend store.</p>
43 * <P>If a salt value is provided, the same salt value must be use when calling the {@link
44 * #isPasswordValid(String, String, Object)} method. Note that a specific implementation may choose to ignore the
45 * salt value (via <code>null</code>), or provide its own.</p>
46 *
47 * @param rawPass the password to encode
48 * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
49 * <code>null</code> value is legal.
50 *
51 * @return encoded password
52 *
53 * @throws DataAccessException DOCUMENT ME!
54 */
55 String encodePassword(String rawPass, Object salt)
56 throws DataAccessException;
57
58 /**
59 * <p>Validates a specified "raw" password against an encoded password.</p>
60 * <P>The encoded password should have previously been generated by {@link #encodePassword(String,
61 * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>), and then
62 * compared it with the presented <code>encPass</code>.</p>
63 * <p>For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.</p>
64 *
65 * @param encPass a pre-encoded password
66 * @param rawPass a raw password to encode and compare against the pre-encoded password
67 * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
68 * <code>null</code> value is legal.
69 *
70 * @return true if the password is valid , false otherwise
71 *
72 * @throws DataAccessException DOCUMENT ME!
73 */
74 boolean isPasswordValid(String encPass, String rawPass, Object salt)
75 throws DataAccessException;
76 }