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

📄 hashcypher.java

📁 是一个专门设计用于触摸屏的POS(point of sales)应用软件
💻 JAVA
字号:
//    Tina POS is a point of sales application designed for touch screens.//    Copyright (C) 2005 Adrian Romero Corchado.//    http://sourceforge.net/projects/tinapos////    This program is free software; you can redistribute it and/or modify//    it under the terms of the GNU General Public License as published by//    the Free Software Foundation; either version 2 of the License, or//    (at your option) any later version.////    This program is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//    GNU General Public License for more details.////    You should have received a copy of the GNU General Public License//    along with this program; if not, write to the Free Software//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USApackage net.adrianromero.tpv.util;import java.awt.Component;import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import javax.swing.ImageIcon;import javax.swing.JOptionPane;import net.adrianromero.beans.JPasswordDialog;import net.adrianromero.tpv.forms.AppLocal;public class Hashcypher {            /** Creates a new instance of Hashcypher */    public Hashcypher() {    }                public static boolean authenticate(String sPassword, String sHashPassword) {        if (sHashPassword == null || sHashPassword.equals("") || sHashPassword.startsWith("empty:")) {            return sPassword == null || sPassword.equals("");        } else if (sHashPassword.startsWith("sha1:")) {            return sHashPassword.equals(hashString(sPassword));        } else if (sHashPassword.startsWith("plain:")) {            return sHashPassword.equals("plain:" + sPassword);        } else {            return sHashPassword.equals(sPassword);        }     }        public static String hashString(String sPassword) {                if (sPassword == null || sPassword.equals("")) {            return "empty:";        } else {            try {                MessageDigest md = MessageDigest.getInstance("SHA-1");                md.update(sPassword.getBytes("UTF-8"));                byte[] res = md.digest();                return "sha1:" + StringUtils.byte2hex(res);            } catch (NoSuchAlgorithmException e) {                return "plain:" + sPassword;            } catch (UnsupportedEncodingException e) {                return "plain:" + sPassword;            }        }    }        public static String changePassword(Component parent, String sOldPassword) {                String sPassword = JPasswordDialog.showEditPassword(parent,                                 AppLocal.getIntString("Label.Password"),                 AppLocal.getIntString("label.passwordold"),                new ImageIcon(Hashcypher.class.getResource("/net/adrianromero/images/password.png")));        if (sPassword != null) {            if (Hashcypher.authenticate(sPassword, sOldPassword)) {                sPassword = JPasswordDialog.showEditPassword(parent,                                         AppLocal.getIntString("Label.Password"),                         AppLocal.getIntString("label.passwordnew"),                        new ImageIcon(Hashcypher.class.getResource("/net/adrianromero/images/password.png")));                if (sPassword != null) {                    String sPassword2 = JPasswordDialog.showEditPassword(parent,                                             AppLocal.getIntString("Label.Password"),                             AppLocal.getIntString("label.passwordrepeat"),                            new ImageIcon(Hashcypher.class.getResource("/net/adrianromero/images/password.png")));                    if (sPassword2 != null) {                        if (sPassword.equals(sPassword2)) {                            return  Hashcypher.hashString(sPassword);                        } else {                            JOptionPane.showMessageDialog(parent, AppLocal.getIntString("message.changepassworddistinct"), AppLocal.getIntString("message.title"), JOptionPane.WARNING_MESSAGE);                        }                    }                }                              } else {                JOptionPane.showMessageDialog(parent, AppLocal.getIntString("message.BadPassword"), AppLocal.getIntString("message.title"), JOptionPane.WARNING_MESSAGE);           }        }        return null;    }}

⌨️ 快捷键说明

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