国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

開源密碼管理軟件

2019-11-18 16:15:40
字體:
來源:轉載
供稿:網友

/**
 * 版權所有, * 作者:陳躍峰
 * email:cqUCyf@263.net
 * 該代碼,您可以任意使用,轉貼,但是請在任何時候都不要刪除該信息
 * 若以商業方式使用,請于作者聯系
 * 版本號:0.20
 */
package pm.core;

import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.rms.*;


/**
 * 密碼管理軟件
 * 實現將常用的密碼信息都保存在手機中。如銀行密碼、郵箱密碼等等,該軟件不訪問網絡,所以絕對不會泄漏您的個人隱私。
 */

public class PassWordManagerMidlet extends MIDlet implements CommandListener {
 //顯示對象
    Display display;
    //主題
    String title = "開源密碼管理軟件";
    //軟件主界面
    List lstMain;
   
    //主界面確定按鈕
    Command cmdEnterMain;
    //退出按鈕
    Command cmdExit;
   
    //增加密碼界面
    Form frmAddPassword;
    //密碼ID
    TextField tfId;
    //密碼
    TextField tfPsswordAdd;
    //確認密碼
    TextField tfConfirmPasswordAdd;
    //備注信息
    TextField tfRemark;
    //確定按鈕
    Command cmdEnterAdd;
    //返回按鈕
    Command cmdBackAdd;
   
    //查看密碼主界面
    List lstView;
    //查看詳細信息按鈕
    Command cmdInfo;
    //返回按鈕
    Command cmdBackViewMain;
     //查看密碼中的顯示詳細信息窗口
     TextBox tbViewInfo;
     //刪除按鈕
     Command cmdDelView;
     //修改按鈕
     Command cmdModify;
     //返回按鈕
     Command cmdBackViewInfo;
     
     //查看密碼中的修改密碼窗口
     Form frmViewModifyPassword;
     //密碼文本框
     TextField tfPasswordView;
     //確認密碼文本框
     TextField tfConfirmPasswordView;
     //修改按鈕
     Command cmdModifyView;
     //返回按鈕
     Command cmdBackViewModify;
   
   
    //設置密碼界面
    Form frmSetPassword;
    //密碼
    TextField tfPassword;
    //確認密碼
    TextField tfConfirmPassword;
    //確定按鈕
    Command cmdEnterSetPassword;
    //返回按鈕
    Command cmdBackSetPassword;
    //刪除按鈕
    Command cmdDelSetPassword;
   
    //幫助界面
    Form frmHelp;
    //幫助界面的返回按鈕
    Command cmdBackHelp;
   
    //關于界面
    Form frmAbout;
    //關于界面的返回按鈕
    Command cmdBackAbout;
   
    //提示窗口
    Alert alert;
   
    //啟動時的輸入密碼界面
    Form frmStartPassword;
    //密碼輸入文本框
    TextField tfStartPassword;
    //密碼界面中的確定按鈕
    Command cmdEnterStart;
   
    //密碼
    String password = "";
   
    //記錄對象
    RecordStore rs;
    //存儲密碼ID內容
    String[] id;
    //保存顯示的密碼ID對應的索引號,數組下標為0的代表第一個密碼ID,1的代表第二個,依次類推
    int[] idIndex;
       
 /**
  * 初始化界面元素
  */
    public PasswordManagerMidlet() {
      //初始化顯示對象
        display = Display.getDisplay(this);
        //初始化主窗體
  lstMain = new List(title,List.IMPLICIT);
  lstMain.append("增加",null);
  lstMain.append("察看",null);
  lstMain.append("設置",null);
  lstMain.append("幫助",null);
  lstMain.append("關于",null);
  
  //初始化主界面確定按鈕
  cmdEnterMain = new Command("確定",Command.OK,1);
  //添加到主界面
  lstMain.addCommand(cmdEnterMain);
  
  //初始化退出按鈕
  cmdExit = new Command("退出",Command.EXIT,1);
  //添加到主界面
  lstMain.addCommand(cmdExit);
  
  //初始化增加密碼界面
  frmAddPassword = new Form(title);
  tfId = new TextField("密碼ID:","",100,TextField.ANY);
  tfPsswordAdd = new TextField("密碼:","",20,TextField.PASSWORD);
  tfConfirmPasswordAdd = new TextField("1確認密碼:","",20,TextField.PASSWORD);
  tfRemark = new TextField("備注:","",100,TextField.ANY);
  cmdEnterAdd = new Command("確定",Command.OK,1);
  cmdBackAdd = new Command("返回",Command.BACK,1);
  
  //添加到增加密碼界面
  frmAddPassword.append(tfId);
  frmAddPassword.append(tfPsswordAdd);
  frmAddPassword.append(tfConfirmPasswordAdd);
  frmAddPassword.append(tfRemark);
  frmAddPassword.addCommand(cmdEnterAdd);
  frmAddPassword.addCommand(cmdBackAdd);
  
  //初始化查看密碼主界面
  lstView = new List(title,List.IMPLICIT);
  cmdInfo = new Command("查看",Command.SCREEN,1);
  cmdBackViewMain = new Command("返回",Command.BACK,1);
  //添加到查看密碼主界面
  lstView.addCommand(cmdInfo);
  lstView.addCommand(cmdBackViewMain);
   //初始化查看密碼詳細信息界面
   tbViewInfo = new TextBox("詳細信息","",200,TextField.ANY);
   cmdDelView =new Command("刪除",Command.SCREEN,1);
   cmdModify = new Command("修改",Command.SCREEN,1);
   cmdBackViewInfo =new Command("返回",Command.BACK,1);
   //添加到查看密碼詳細信息界面中
   tbViewInfo.addCommand(cmdDelView);
   tbViewInfo.addCommand(cmdModify);
   tbViewInfo.addCommand(cmdBackViewInfo);
   
   //初始化查看密碼中的修改密碼界面
   frmViewModifyPassword = new Form("修改密碼");
   tfPasswordView = new TextField("密碼:","",20,TextField.PASSWORD);
   tfConfirmPasswordView = new TextField("確認密碼:","",20,TextField.PASSWORD);
   cmdModifyView = new Command("確定",Command.OK,1);
   cmdBackViewModify = new Command("返回",Command.BACK,1);
   //添加到修改密碼界面
   frmViewModifyPassword.append(tfPasswordView);
   frmViewModifyPassword.append(tfConfirmPasswordView);
   frmViewModifyPassword.addCommand(cmdModifyView);
   frmViewModifyPassword.addCommand(cmdBackViewModify);
  
  
  //初始化設置密碼界面
  frmSetPassword = new Form("設置密碼");
  tfPassword = new TextField("密碼:","",20,TextField.PASSWORD);
  tfConfirmPassword = new TextField("確認密碼:","",20,TextField.PASSWORD);
  cmdEnterSetPassword = new Command("確定",Command.OK,1);
  cmdBackSetPassword = new Command("返回",Command.BACK,1);
  cmdDelSetPassword = new Command("刪除",Command.SCREEN,1);
  //添加到設置密碼界面
  frmSetPassword.append(tfPassword);
  frmSetPassword.append(tfConfirmPassword);
  frmSetPassword.addCommand(cmdEnterSetPassword);
  frmSetPassword.addCommand(cmdBackSetPassword);
  frmSetPassword.addCommand(cmdDelSetPassword); 
  
  //初始化幫助界面
  frmHelp = new Form("幫助");
  frmHelp.append("開源密碼管理軟件是一款幫助您管理各種密碼的軟件,/"增加/"中可以增加新的密碼,/"察看/"中可以查看、修改和刪除已有的密碼,/"設置/"中可以進行該軟件的進入密碼設置。");
  //初始化返回按鈕
  cmdBackHelp = new Command("返回",Command.BACK,1);
  //添加到幫助界面
  frmHelp.addCommand(cmdBackHelp);
  
        //初始化關于界面
        frmAbout = new Form("關于...");
        frmAbout.append("版權所有 2004-   作者:陳躍峰  email:cqucyf@263.net   歡迎您提出該版本的更新建議");
        //初始化返回按鈕
        cmdBackAbout = new Command("返回",Command.BACK,1);
        //添加到關于界面
        frmAbout.addCommand(cmdBackAbout);
       
        //初始化提示窗口
        alert = new Alert(title);
       
        //初始化啟動時的密碼界面
        frmStartPassword = new Form(title);
        //初始化啟動時的密碼輸入文本框
        tfStartPassword = new TextField("請輸入密碼","",20,TextField.PASSWORD);
        //初始化確定按鈕
        cmdEnterStart = new Command("確定",Command.OK,1);
       
        //添加到密碼界面中
        frmStartPassword.append(tfStartPassword);
        frmStartPassword.addCommand(cmdEnterStart);
        frmStartPassword.addCommand(cmdExit);       
       
        //事件處理
        lstMain.setCommandListener(this);
        frmHelp.setCommandListener(this);
        frmAbout.setCommandListener(this);
        frmStartPassword.setCommandListener(this);
        frmSetPassword.setCommandListener(this);
        frmAddPassword.setCommandListener(this);
        lstView.setCommandListener(this);
        tbViewInfo.setCommandListener(this);
        frmViewModifyPassword.setCommandListener(this);
       
      /*  //測試代碼,添加記錄
        try{
      rs = RecordStore.openRecordStore("password",true);
      rs.setRecord(1,new String("123456").getBytes(),0,6);
 
  //    System.out.PRintln(i);
      rs.closeRecordStore();         
        }catch(Exception e){
         System.out.println("測試代碼--添加記錄:" + e);
        }
      //測試代碼,刪除所有記錄集
      try{
       RecordStore.deleteRecordStore("id");
       RecordStore.deleteRecordStore("pwd");
       RecordStore.deleteRecordStore("remark");
       RecordStore.deleteRecordStore("flag");
       //RecordStore.deleteRecordStore("password");
      }catch(Exception e){
       System.out.println(e);
      }        */


    }
 /**
  * 啟動方法
  */
    public void startApp () {
     try{
      //打開密碼紀錄
      rs = RecordStore.openRecordStore("password",false);
      //讀取密碼
      byte[] b = rs.getRecord(1);
      password = new String(b,"iso8859_1");
      //關閉記錄
      rs.closeRecordStore();
      //顯示輸入密碼界面
      display.setCurrent(frmStartPassword);
      
     }catch(Exception e){
      //沒有密碼記錄,則顯示主界面
      display.setCurrent(lstMain);
     }
    }

    public void destroyApp(boolean unconditional) {
    }

    public void pauseApp() {
    }
 
 /**
  * 事件處理
  */
    public void commandAction(Command c, Displayable s) {
     //處理啟動時的密碼窗口中的確定按鈕事件
     if(c == cmdEnterStart){
      //用戶輸入的密碼
      String pwd = tfStartPassword.getString();
      //判斷用戶輸入是否為空
      if(pwd == null pwd.length() ==0){ //輸入為空
       //顯示警告提示
       displayAlert("請輸入密碼!");
      }else{ //輸入不為空
       //比較密碼
       if(pwd.equals(password)){ //密碼正確
        //顯示主界面
        display.setCurrent(lstMain);
       }else{//密碼錯誤
        //顯示警告提示
        displayAlert("密碼錯誤,請重新輸入!");
       }
      }
     }
   
     //處理退出事件
     if(c == cmdExit){
            destroyApp(false);
            notifyDestroyed();
        }
       
        //處理主界面中的選擇
        if(c == cmdEnterMain){
         int index = lstMain.getSelectedIndex();
         
         //System.out.println(index);
         //選擇“增加”
         if(index == 0){
          //顯示增加密碼界面
          display.setCurrent(frmAddPassword);
         }
         //選擇“查看”
         if(index == 1){
          
          //獲得密碼ID列表
          try{
           //打開flag記錄集
           RecordStore rsTemp = RecordStore.openRecordStore("flag",true);
           //打開ID記錄集
           rs = RecordStore.openRecordStore("id",true);
           //獲得記錄集中記錄的個數
           int num = rs.getNumRecords();
           //初始化密碼ID索引數組
           idIndex = new int[num];
           
           //創建存儲ID的數組
           id = new String[num];
           //將ID信息讀入ID數組中
           int j = 0;//代表數組的下標
           for(int i = 1;i <= num;i++){
            //如果flag記錄集中的值為0,則讀,1代表刪除,則不讀
            String flagTemp = new String(rsTemp.getRecord(i));
            //System.out.println("" + i + ":" + flagTemp);
            if(flagTemp.equals("0")){
             idIndex[j] = i;  //獲得顯示的內容于記錄集中的索引號的對應關系
             id[j] = new String(rs.getRecord(i),"gb2312");
             j++;
            }
           }
           //System.out.println("lstView.size() 2:" + lstView.size());
               //清空lstView中的顯示
          for(int i = lstView.size() - 1;i >= 0;i--){
           lstView.delete(i);
           //System.out.println("lstView.delete(" + i + ")");
          }
           //將ID信息顯示在lstView中
           for(int i = 0;i < j;i++){
            lstView.append(id[i],null);
            //System.out.println("lstView.append(" + i + ")");
           }
           
           //顯示lstView
           display.setCurrent(lstView);
          }catch(Exception e){
           System.out.println("查看密碼失敗:" +e);
           //查看失敗
           displayAlert("查看密碼失敗!");


          }
         }
         //選擇“設置”
         if(index == 2){
          //顯示設置密碼界面
          display.setCurrent(frmSetPassword);
         }
         //選擇“幫助”
         if(index == 3){
          //顯示幫助界面
          display.setCurrent(frmHelp);
         }
         //選擇“關于”
         if(index == 4){
          //顯示關于界面
          display.setCurrent(frmAbout);
         }
         
         //未選擇
         if(index == -1){
          displayAlert("請選擇您要察看的項目");
         }
        }
       
        //處理設置密碼界面中的返回按鈕
        if(c == cmdBackSetPassword){
         //顯示主界面
         display.setCurrent(lstMain);
        }
       
        //處理設置密碼界面中的確定按鈕
        if(c == cmdEnterSetPassword){
         //密碼
         String pwd1 = tfPassword.getString();
         //確認密碼
         String pwd2 = tfConfirmPassword.getString();
         //判斷用戶是否輸入為空
         if(pwd1.length() !=0 && pwd2.length() != 0){
          //判斷密碼和確認密碼是否相同
          if(pwd1.equals(pwd2)){
           //設置密碼
           try{
            //打開密碼紀錄
         rs = RecordStore.openRecordStore("password",true);
         //System.out.println("rs.getNumRecords():" + rs.getNumRecords());
         //判斷是否已設置密碼
         if(rs.getNumRecords() > 0){
          //設置密碼
          rs.setRecord(1,pwd1.getBytes(),0,pwd1.length());
         }else{ //未設置密碼
          rs.addRecord(pwd1.getBytes(),0,pwd1.length());
         }
         //關閉記錄
         rs.closeRecordStore();
         //提示修改成功
         displayAlert("密碼設置成功");
           }catch(Exception e){
            //System.out.println(e);
            //設置失敗
            displayAlert("密碼設置失敗!");
           }
          }else{
           //提示用戶密碼和確認密碼必須相同
           displayAlert("密碼和確認密碼不相同");
          }
         }else{
          //提示用戶密碼和確認密碼不能為空
          displayAlert("請檢查密碼和確認密碼是否為空!");
         }
        }
       
        //處理幫助界面中的返回按鈕
        if(c == cmdBackHelp){
         //顯示主界面
         display.setCurrent(lstMain);
        }
       
        //處理關于界面中的返回按鈕
        if(c == cmdBackAbout){
         //顯示主界面
         display.setCurrent(lstMain);
        }
       
        //處理增加密碼界面中的返回按鈕
        if(c == cmdBackAdd){
         //顯示主界面
         display.setCurrent(lstMain);
        }
       
        //處理增加密碼界面中的確定按鈕事件
        if(c == cmdEnterAdd){
         String idAdd = tfId.getString(); //id


         String passwordAdd = tfPsswordAdd.getString();//密碼
         String confirmPasswordAdd = tfConfirmPasswordAdd.getString();//確認密碼
         String remarkAdd = tfRemark.getString();//備注
         //判斷是否完整輸入,備注可以為空
         if(idAdd.length() != 0 && passwordAdd.length() != 0 && confirmPasswordAdd.length() != 0){
          //比較密碼和確認密碼是否相同
          if(passwordAdd.equals(confirmPasswordAdd)){
           //寫入記錄集中
           try{
      
            //寫入ID
            rs = RecordStore.openRecordStore("id",true);
            rs.addRecord(idAdd.getBytes(),0,idAdd.length());
            rs.closeRecordStore();
            //寫入密碼
            rs = RecordStore.openRecordStore("pwd",true);
            rs.addRecord(passwordAdd.getBytes("iso8859_1"),0,passwordAdd.length());
            rs.closeRecordStore();
            //寫入備注
            rs = RecordStore.openRecordStore("remark",true);
            rs.addRecord(remarkAdd.getBytes("iso8859_1"),0,remarkAdd.length());
            rs.closeRecordStore();
            //寫入是否刪除的標記,0代表正常,1代表刪除
            rs = RecordStore.openRecordStore("flag",true);
            rs.addRecord(new String("0").getBytes(),0,1);
            rs.closeRecordStore();
            
            //提示密碼增加成功
            displayAlert("密碼增加成功!");
           }catch(Exception e){
            //顯示警告信息
            displayAlert("增加密碼失敗!");
           }
          }else{
           //顯示警告信息
           displayAlert("密碼和確認密碼是否相同!");
          }
         }else{
          //顯示警告信息
          displayAlert("請檢查輸入是否完整!");
         }         
        }
       
      //處理查看密碼主界面中的返回按鈕
      if(c == cmdBackViewMain){
        //顯示主界面
         display.setCurrent(lstMain);       
      }
     
      //處理查看密碼主界面中的查看按鈕事件
      if(c == cmdInfo){
       int index = lstView.getSelectedIndex();  //需要查看的信息id
       //如果沒有記錄,則直接返回
       if(index == -1) return;
       
       //獲得信息
       String s1 = getInfoById(idIndex[index]);
       if(s != null){
        //顯示到tbViewInfo中
        tbViewInfo.setString(s1);
       }else{
        //顯示提示信息,查看失敗
        displayAlert("無法獲得詳細信息");
       }
       //顯示密碼詳細信息界面
       display.setCurrent(tbViewInfo);
      }
     
      //處理密碼詳細信息界面中的返回按鈕事件
      if(c == cmdBackViewInfo){
       //顯示查看密碼主界面
       display.setCurrent(lstView);
      }
     
      //處理密碼詳細信息界面中的修改按鈕事件
      if(c == cmdModify){
       //顯示修改密碼界面
       display.setCurrent(frmViewModifyPassword);
      }
     
      //處理密碼詳細信息界面中的刪除按鈕事件
      if(c == cmdDelView){
       //查看密碼界面中被選中的索引號
       int index = lstView.getSelectedIndex();
       
       //刪除紀錄集中的內容
       try{
        //向記錄集中的flag內容中寫入刪除標記
        rs = RecordStore.openRecordStore("flag",true);
        rs.setRecord(idIndex[index],new String("1").getBytes(),0,1);
        rs.closeRecordStore();
        
        //返回主界面
        display.setCurrent(lstMain);
       }catch(Exception e){
        System.out.println(e);
        //顯示警告信息
        displayAlert("刪除密碼失敗,請重試!");
       }       
      }
     
      //處理修改密碼界面中的返回按鈕事件
      if(c == cmdBackViewModify){
       int index = lstView.getSelectedIndex();  //需要查看的信息id
       //獲得信息
       String s1 = getInfoById(idIndex[index]);
       if(s != null){
        //顯示到tbViewInfo中
        tbViewInfo.setString(s1);
       }else{
        //顯示提示信息,查看失敗
        displayAlert("無法獲得詳細信息");
       }
       //顯示密碼詳細信息界面
       display.setCurrent(tbViewInfo);
      }
     
      //處理修改密碼界面中的修改按鈕事件
      if(c == cmdModifyView){
      //密碼框用戶輸入
       String pwd1 = tfPasswordView.getString();
       //確認密碼框用戶輸入
       String pwd2 = tfConfirmPasswordView.getString();
       //判斷用戶的輸入
       if(pwd1.length() != 0 && pwd2.length() != 0){ //用戶輸入了密碼和確認密碼
        //判斷密碼和確認密碼是否相同
        if(pwd1.equals(pwd2)){//相同
         int index = lstView.getSelectedIndex();  //需要查看的信息id
         //修改密碼
         try{
          //修改密碼
          rs = RecordStore.openRecordStore("pwd",true);
          rs.setRecord(idIndex[index],pwd1.getBytes(),0,pwd1.length());
          rs.closeRecordStore();
          //顯示
          //獲得信息
          String s1 = getInfoById(idIndex[index]);
          if(s != null){
           //顯示到tbViewInfo中
           tbViewInfo.setString(s1);
          }else{
          //顯示提示信息,查看失敗
           displayAlert("無法獲得詳細信息");
          }
          //顯示密碼詳細信息界面
          display.setCurrent(tbViewInfo);
         }catch(Exception e){
          //顯示修改失敗
          displayAlert("修改密碼失敗");
         }
        }else{//不相同
         //顯示密碼和確認密碼不相同
         displayAlert("密碼和確認密碼不同!");
        }
       }else{ //密碼或者確認密碼,用戶未輸入
        //提示用戶輸入
        displayAlert("請檢查輸入是否完整,其中密碼和確認密碼均不能為空!");
       }
      }
     
      //設置進入密碼界面中的刪除按鈕事件
      if(c == cmdDelSetPassword){
       try{
        //判斷用戶是否已設置密碼
        rs = RecordStore.openRecordStore("password",true);
        int numTemp = rs.getNumRecords(); //記錄集中的紀錄數量
        rs.closeRecordStore();
        //用戶已設置密碼
        if(numTemp > 0){   
         //刪除,徹底刪除
         RecordStore.deleteRecordStore("password");
         //提示刪除密碼成功
         displayAlert("刪除密碼成功,請返回!");
        }else{//用戶未設置密碼
         //提示尚未設置密碼
         displayAlert("您尚未設置密碼,無法刪除!");
        }
       }catch(Exception e){
        
        //顯示刪除失敗
        displayAlert("刪除密碼失敗,請重試!");
       }
      }
    }
   
    /**
     *顯示提示或者警告信息
     *@param msg 信息內容
     */
    public final void displayAlert(String msg){
        //設置提示信息
        alert.setString(msg);
        //顯示3秒
        alert.setTimeout(3000);
        display.setCurrent(alert);     
    }
   
    /**
     * 獲得指定id的紀錄內容,包括密碼id,密碼和備注信息
     *
     *
     */
    public final String getInfoById(int id){
     try{
      //密碼ID
      rs = RecordStore.openRecordStore("id",false);
        String idView = new String(rs.getRecord(id),"gb2312");
        rs.closeRecordStore();
        //密碼
        rs = RecordStore.openRecordStore("pwd",false);
        String pwdView = new String(rs.getRecord(id),"gb2312");
        rs.closeRecordStore();
        //備注
        rs = RecordStore.openRecordStore("remark",false);
        String remarkView = new String(rs.getRecord(id),"gb2312");
        rs.closeRecordStore();
        //返回
        return "密碼id:" + idView + "  密碼:" + pwdView + "  備注:" + remarkView;
  }catch(Exception e){
   return null;
  }        
    }
}


(出處:http://m.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延川县| 英德市| 合水县| 同江市| 同心县| 新津县| 平武县| 青海省| 仲巴县| 沙雅县| 庆阳市| 浦县| 随州市| 长顺县| 兴隆县| 海盐县| 石柱| 正蓝旗| 蒲江县| 定州市| 顺昌县| 芷江| 科技| 绍兴市| 伊金霍洛旗| 黄大仙区| 大化| 临邑县| 德化县| 涞水县| 仁寿县| 天门市| 三河市| 潢川县| 房产| 铁岭县| 浮梁县| 玉林市| 温州市| 齐齐哈尔市| 昌邑市|