⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5passwordencrypter.java

📁 一个很好的开源项目管理系统源代码
💻 JAVA
字号:
/* */package net.java.workeffort.infrastructure.encrypt;import org.apache.commons.codec.binary.Base64;import org.apache.commons.codec.digest.DigestUtils;/** * The password encrypter implementation using md5. * @author Antony Joseph */public class Md5PasswordEncrypter implements IPasswordEncrypter {    private static final String SALT = "-a1b2";    /**     * Encodes the password using md5 and returns a Base64 encoded string.     * @param password The password to be encoded     * @return The encoded password     */    public String encryptPassword(String password) {        if (password == null)            password = "";        String passwordSaltStr = password + SALT;        // encode to base64 (ASCII) so we can store in database        byte[] encryptedPassword = Base64.encodeBase64(DigestUtils                .md5(passwordSaltStr));        //System.out.println("encryptedPassword = " + new        // String(encryptedPassword));        return new String(encryptedPassword);    }    public boolean isPasswordValid(String password, String encryptedPassword) {        if (encryptedPassword == null)            throw new IllegalArgumentException(                    "encryptedPassword cannot be null");        if (password == null)            password = "";        return encryptedPassword.equals(encryptPassword(password));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -