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

📄 dynamicpassword.java

📁 手机动态密码产生器
💻 JAVA
字号:
package dynamicP;

import com.cuilichen.usual.*;
import java.lang.Thread;
import java.util.Hashtable;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;


public class DynamicPassword extends MyMIDlet {
    private Welcome welcome;
    private List funcList;
    private List gameList;
    private Form secretKey;
    private Form help;
    private Form alarm;
    private TextField key1TF;
    private TextField key2TF;
    private TextField gameTF;
    private Password password;
    private String functions[] = { "产生密码", "输入密钥", "清除密钥", "系统帮助" };
    private int gameID; //标识Game,RMS主键,alertNum 用来标识alert的前一页是什么
    private int gameIDs[] = { 0, 1, 2, 3, 4, 5 }; //Game的标识
    private boolean showPassword = false;
    private boolean first = true;
    private String gameName;
    private String gameKey;
    private String rsName = "DyPassword";
    private String gameNames[] = { "名称1", "名称2", "名称3", "名称4", "名称5", "名称6" };

    public DynamicPassword() {
    }

    protected void startApp() throws MIDletStateChangeException {
        if(RMS.getNumOfRecords(rsName) == 0) {
            for(int i = 0; i < gameNames.length; i++) {
                RMS.addRecord(rsName, RMS.Int1, gameIDs[i], RMS.Long1, Integer.toString(gameIDs[i]), gameNames[i], "1234567890123456789", false);
            }
        }

        try {
            welcome = new Welcome("/MoAndBox.png", "/MoAndBox.png");
            display.setCurrent(welcome);
            Thread.sleep(1000);
            welcome = new Welcome("/ELine.png", "/ELine.png");
            display.setCurrent(welcome);
            Thread.sleep(1000);
            welcome = new Welcome("/welcome.png", "/welcome2.png");
            display.setCurrent(welcome);
            Thread.sleep(1500);
        } catch(Exception e) {
            notifyAll();
        }

        initGameList();
    }

    protected void pauseApp() {
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    }

    void initGameList() {
        gameList = new List("选择", List.IMPLICIT);

        Appointment apps[] = RMS.getRecords(rsName);

        for(int i = 0; i < apps.length; i++) {
            gameNames[i] = apps[i].getStr2();
            gameList.append(">>" + gameNames[i], null);
        }

        gameList.addCommand(CM.enterCM);
        gameList.addCommand(CM.exitCM);
        gameList.setCommandListener(this);
        display.setCurrent(gameList);
    }

    void initFuncList() {
        Appointment apps[] = RMS.getRecords(rsName); //重写游戏名称

        for(int i = 0; i < apps.length; i++) {
            gameNames[i] = apps[i].getStr2();
        }

        funcList = new List("功能选择", List.IMPLICIT);

        for(int i = 0; i < functions.length; i++) {
            funcList.append(">>" + functions[i], null);
        }

        funcList.addCommand(CM.enterCM);
        funcList.addCommand(CM.backCM);
        funcList.setCommandListener(this);
        display.setCurrent(funcList);
    }

    void initPassword(int _gameID, String _gameKey, String _gameName) {
        password = new Password(_gameID, _gameKey, _gameName);
        password.addCommand(CM.exitCM);
        password.addCommand(CM.backCM);
        password.setCommandListener(this);
        display.setCurrent(password);
    }

    void initSecretKey() {
        secretKey = new Form("");
        key1TF = new TextField("密钥1", "", 10, TextField.NUMERIC);
        key2TF = new TextField("密钥2", "", 11, TextField.NUMERIC);
        gameTF = new TextField("名称", gameName, 64, TextField.ANY);
        secretKey.append(key1TF);
        secretKey.append(key2TF);
        secretKey.append(gameTF);
        secretKey.addCommand(CM.backCM);
        secretKey.addCommand(CM.enterCM);
        secretKey.setCommandListener(this);
        display.setCurrent(secretKey);
    }

    void initHelpForm() {
        help = new Form("系统帮助");
        help.append("动态口令卡系统:\n开发:北京尚易达科技有限责任公司\n发行:北京亿联星空技术有限公司\n系统简介:\n动态口令卡系统,基于当前被国家安全系统和金融系统广泛采用的动态口令认证技术,旨在保护用户的虚拟资产的安全。使用动态密码认证机制,真正实现了网络身份认证的安全。\n该系统支持列表请见www.sunnitech.com(持续更新中)。\n得到密钥的方法请访问相关运营商主页。\n您也可以免费获取测试密钥以验证软件的适用性,详情请浏览www.sunnitech.com。\n北京尚易达科技有限责任公司地址:\n北京市海淀区万泉河路68号紫金大厦1109室\n联系电话:\n010-82659565\n客服eMail:\nservice@sunnitech.com\n北京亿联星空技术有限公司介绍:简称亿联星空,由一批多年从事电信增值服务系统开发、市场研究及销售的专业人士创办。主要从事信息技术与信息服务的研究、开发与推广,是一个具有自主知识产权、具有现代企业治理结构、具有明确的市场定位与完整的发展战略、以及具有先进企业文化的高科技企业。\n公司地址:\n北京市阜成路73号裕惠大厦B座504,505室\n联系电话:\n(010)88511717\neMail:\nService@eline.cn");
        help.addCommand(CM.backCM);
        help.setCommandListener(this);
        display.setCurrent(help);
    }

    void initAlarm() {
        alarm = new Form("");
        alarm.append("警告! \n您将删除密钥!\n确认您的操作?");
        alarm.addCommand(CM.enterCM);
        alarm.addCommand(CM.backCM);
        alarm.setCommandListener(this);
        display.setCurrent(alarm);
    }

    public void showAlert(int status, String reason, Displayable _preAlert) {
        alert = new Form("");

        if(status == 1) {
            alert.setTitle("成功");
            alert.append("恭喜!操作成功!\n");
        } else if(status == 2) {
            alert.setTitle("失败");
            alert.append("注意:操作失败!\n失败原因:\n" + reason);
        }

        alert.addCommand(CM.backCM);
        alert.addCommand(CM.exitCM);
        alert.setCommandListener(this);
        display.setCurrent(alert);
        preAlert = _preAlert; //记录输出警告的页面,用于返回。
    }

    private int checkKey(String k, String k2) {
        int result = -1;

        if((k.length() == 10) && (k2.length() == 11)) { //检查密钥长度
            k = k + k2;

            int kInt[] = new int[21];

            for(int i = 0; i < 21; i++) {
                kInt[i] = Integer.valueOf(k.substring(i, i + 1)).intValue();
            }

            int Sum = 0;
            int PrimeNumber[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, //加权数组
                29, 31, 37, 41, 43, 47, 53, 59, 61, 67 };

            for(int i = 0; i < 19; i++) {
                Sum += (kInt[i] * PrimeNumber[i]);
            }

            int Sign = (kInt[19] * 10) + kInt[20]; //第20,21位用于校验

            if((Sum % 97) == Sign) { //密钥校验成功
                result = 0;
            } else {
                result = 2; //密钥校验未通过
            }
        } else {
            result = 4; //密钥长度错误
        }

        return result;
    }

    public void commandAction(Command c, Displayable d) {
        try {
            Screen screen = (Screen)d;

            if(screen == gameList) {
                if(c == CM.enterCM) {
                    int orderNumber = gameList.getSelectedIndex();
                    gameID = gameIDs[orderNumber];
                    gameName = gameNames[orderNumber];
                    initFuncList();
                    display.setCurrent(funcList);
                    orderNumber = 0;
                }

                if(c == CM.exitCM) {
                    myExit();
                }
            } else if(screen == funcList) {
                if(c == CM.enterCM) {
                    int orderNumber = funcList.getSelectedIndex();

                    if(orderNumber == 0) { //产生密码功能

                        int j = RMS.getIndex(rsName, Integer.toString(gameID));
                        Appointment app = RMS.getRecord(rsName, j);

                        if(app.getWroteFlag() == false) {
                            showAlert(2, "密钥尚未输入!\n请先输入密钥!", funcList);
                        } else {
                            initPassword(gameID, app.getStr3(), app.getStr2());
                        }
                    } else if(orderNumber == 1) { //写入密钥功能

                        int j = RMS.getIndex(rsName, Integer.toString(gameID));
                        Appointment app = RMS.getRecord(rsName, j);

                        if(app.getWroteFlag() == true) {
                            showAlert(2, "密钥已经写入.\n请使用另一个.", funcList);
                        } else {
                            initSecretKey();
                        }
                    } else if(orderNumber == 2) { //清除密钥,警告
                        initAlarm();
                    } else if(orderNumber == 3) { //系统帮助
                        initHelpForm();
                    }
                }

                if(c == CM.backCM) {
                    initGameList();
                }
            } else if(screen == secretKey) { //当前显示的是输入密钥页面

                if(c == CM.enterCM) {
                    String content = key1TF.getString();
                    String content2 = key2TF.getString();
                    int result = checkKey(content, content2);

                    if(result == 0) { //密钥通过校验

                        String theKey = (content + content2).substring(0, 19);
                        int j = RMS.getIndex(rsName, Integer.toString(gameID));

                        if(RMS.setRecord(rsName, j, RMS.Int1, gameID, RMS.Long1, Integer.toString(gameID), gameTF.getString(), theKey, true) == true) {
                            showAlert(1, "", funcList);
                        } else {
                            showAlert(2, "", secretKey);
                        }
                    } else if(result == 4) {
                        showAlert(2, "密码长度错误.\n请检查密码长度.", secretKey);
                    } else if(result == 2) {
                        showAlert(2, "密码未通过校验.\n请检查输入.", secretKey);
                    } else {
                        showAlert(2, "发生未定义错误!", secretKey);
                    }
                }

                if(c == CM.backCM) {
                    initFuncList();
                }
            } else if(screen == help) {
                if(c == CM.backCM) {
                    initFuncList();
                }
            } else if(screen == alarm) {
                if(c == CM.enterCM) { //清除密钥,针对单个游戏

                    int j = RMS.getIndex(rsName, Integer.toString(gameID));

                    if(RMS.setRecord(rsName, j, RMS.Int1, gameID, RMS.Long1, Integer.toString(gameID), gameNames[gameID], "1234567890123456789", false) == true) {
                        showAlert(1, "", funcList);
                    } else {
                        showAlert(2, "", secretKey);
                    }
                }

                if(c == CM.backCM) {
                    initFuncList();
                }
            } else if(screen == alert) {
                if(c == CM.backCM) {
                    if(preAlert == funcList) { //前一页是list
                        initFuncList();
                    } else if(preAlert == secretKey) { //前一页是secretKey
                        initSecretKey();
                    }
                } else if(c == CM.exitCM) {
                    myExit();
                }
            }
        } catch(Exception e) {
            try {
                Canvas canvas = (Canvas)d;

                if(canvas == password) {
                    if(c == CM.backCM) {
                        password.setLiving(false);

                        try {
                            Thread.sleep(1000);
                        } catch(Exception ee) {
                        }

                        initFuncList();
                    }

                    if(c == CM.exitCM) {
                        myExit();
                    }
                }
            } catch(Exception ee) {
            }
        }
    }

    public void show(Displayable d, Hashtable h) {
    }
}

⌨️ 快捷键说明

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