|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Md5PasswordEncoder.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 | /* Copyright 2004 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.apache.commons.codec.binary.Base64; | |
| 19 | import org.apache.commons.codec.digest.DigestUtils; | |
| 20 | ||
| 21 | ||
| 22 | /** | |
| 23 | * <p> | |
| 24 | * MD5 implementation of PasswordEncoder. | |
| 25 | * </p> | |
| 26 | * | |
| 27 | * <p> | |
| 28 | * If a <code>null</code> password is presented, it will be treated as an empty | |
| 29 | * <code>String</code> ("") password. | |
| 30 | * </p> | |
| 31 | * | |
| 32 | * <P> | |
| 33 | * As MD5 is a one-way hash, the salt can contain any characters. | |
| 34 | * </p> | |
| 35 | * | |
| 36 | * @author colin sampaleanu | |
| 37 | * @author Ben Alex | |
| 38 | * @version $Id: Md5PasswordEncoder.java,v 1.4 2005/11/17 00:55:49 benalex Exp $ | |
| 39 | */ | |
| 40 | public class Md5PasswordEncoder extends BaseDigestPasswordEncoder | |
| 41 | implements PasswordEncoder { | |
| 42 | //~ Methods ================================================================ | |
| 43 | ||
| 44 | 4 | public boolean isPasswordValid(String encPass, String rawPass, Object salt) { |
| 45 | 4 | String pass1 = "" + encPass; |
| 46 | 4 | String pass2 = encodeInternal(mergePasswordAndSalt(rawPass, salt, false)); |
| 47 | ||
| 48 | 4 | return pass1.equals(pass2); |
| 49 | } | |
| 50 | ||
| 51 | 2 | public String encodePassword(String rawPass, Object salt) { |
| 52 | 2 | return encodeInternal(mergePasswordAndSalt(rawPass, salt, false)); |
| 53 | } | |
| 54 | ||
| 55 | 6 | private String encodeInternal(String input) { |
| 56 | 6 | if (!getEncodeHashAsBase64()) { |
| 57 | 3 | return DigestUtils.md5Hex(input); |
| 58 | } | |
| 59 | ||
| 60 | 3 | byte[] encoded = Base64.encodeBase64(DigestUtils.md5(input)); |
| 61 | ||
| 62 | 3 | return new String(encoded); |
| 63 | } | |
| 64 | } |
|
||||||||||