充满抛瓦密码生成器3

import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

class main1 {
   public static void clipboard(String text) {
      Clipboard clipboard1 = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable txt = new StringSelection(text);
      clipboard1.setContents(txt, null);
   }
}


public class Main {
   public static void main(String[] args) {
      String[] option1 = {"继续", "查看更新特性"};
      int u = JOptionPane.showOptionDialog(null, new JLabel("<html><h2><font color='purple'," + "size=10>你好," + "欢迎来到密码生成器3.0版本" + "<br>" + "</font><font " + "color='pink',size=3> " + "我是充满抛瓦制作的哦~</font></h2></html>"), "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option1, option1[0]);
      if (u == 0) {
         Map<String, String> map = new HashMap<>();
         String[] p1 = {"写入", "查询"};
         int p = JOptionPane.showOptionDialog(null, "请选择你的选项:", "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, p1, p1[0]);
         if (p == 0) {
            String[] p9 = {"自行写入", "辅助生成"};
            int obj2 = JOptionPane.showOptionDialog(null, "请选择下一个步骤", "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, p9, p9[0]);
            if (obj2 == 0) {
               String key = JOptionPane.showInputDialog(null, "请输入密码名称:");
               String value = JOptionPane.showInputDialog(null, "请输入对应的密码:");
               map.put(key, value);
               mapWrite(key, value);
            } else if (obj2 == 1) {
               Random random = new Random();//生成随机数
               String string0 = JOptionPane.showInputDialog(null, "输入密码名称");
               String[] options = {"生成低强度密码", "生成中等强度密码", "生成高强度密码", "生成超高强度密码", "生成密码提示"};
               Object object1 = JOptionPane.showInputDialog(null, "请选择你下面需要的步骤:", "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
               if (object1 != "生成密码提示") {
                  String num = JOptionPane.showInputDialog(null, "请输入你需要几位数的密码:");
                  int num1 = Integer.parseInt(num);
                  char[] chars = new char[num1];
                  String[] option2 = {"小写字母+大写字母", "小写字母+数字", "大写字母+数字"};
                  String[] option5 = {"纯数字", "纯小写字母", "纯大写字母"};
                  if (object1 == "生成高强度密码") {
                     for (int i = 0; i < num1; i++) {
                        int int1 = random.nextInt(48, 122);
                        if (int1 >= 48 && int1 <= 57 || int1 >= 65 && int1 <= 90 || int1 >= 97 && int1 <= 122)
                           chars[i] = (char) int1;
                     }
                  } else if (object1 == "生成超高强度密码") {
                     for (int i = 0; i < num1; i++) {
                        int int1 = random.nextInt(33, 126);
                        chars[i] = (char) int1;
                     }
                  } else if (object1 == "生成低强度密码") {
                     int object3 = JOptionPane.showOptionDialog(null, "请选择你的选项:", "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option5, option5[0]);
                     if (object3 == 0) {
                        for (int i = 0; i < num1; i++) {
                           int int1 = random.nextInt(48, 57);
                           chars[i] = (char) int1;
                        }
                     } else if (object3 == 1) {
                        for (int i = 0; i < num1; i++) {
                           int int1 = random.nextInt(97, 122);
                           chars[i] = (char) int1;
                        }
                     } else if (object3 == 2) {
                        for (int i = 0; i < num1; i++) {
                           int int1 = random.nextInt(65, 90);
                           chars[i] = (char) int1;
                        }
                     }
                  } else if (object1 == "生成中等强度密码") {
                     int ob6 = JOptionPane.showOptionDialog(null, "请选择你的选项:", "欢迎来到充满抛瓦的密码生成/查询器", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option2, option2[0]);
                     for (int i = 0; i < num1; i++) {
                        int int1 = random.nextInt(48, 122);
                        if (ob6 == 0) {
                           if (int1 >= 65 && int1 <= 90 || int1 >= 97 && int1 <= 122)
                              chars[i] = (char) int1;
                        } else if (ob6 == 1) {
                           if (int1 >= 48 && int1 <= 57 || int1 >= 97 && int1 <= 122)
                              chars[i] = (char) int1;
                        } else if (ob6 == 2) {
                           if (int1 >= 65 && int1 <= 90 || int1 >= 97 && int1 <= 122)
                              chars[i] = (char) int1;
                        }
                     }
                  }
                  String string2 = String.valueOf(chars);
                  JOptionPane.showMessageDialog(null, string0 + "的密码是:" + string2);
                  String[] option3 = {"复制到剪贴板", "保存到内部库"};
                  int ob2 = JOptionPane.showOptionDialog(null, new JLabel("<html><h2" + "><font " + "color='blue'," + "size=5" + ">请选择你的下个步骤</font" + "></h2></html>"), "询问", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option3, option3[0]);
                  if (ob2 == 0) {
                     main1.clipboard(string0 + "的密码是:" + string2);
                     //生成剪贴板输入流
                     mapWrite(string0, string2);
                  }
                  if (ob2 == 1) {
                     mapWrite(string0, string2);          
                  }
               } else if (object1 == "生成密码提示") {
                  JOptionPane.showMessageDialog(null, """
                                       低强度密码:由纯数字或纯小写字母或纯大写字母组成;
                                       中等强度密码:由数字、小写字母、大写字母中的其中两种组成;
                                       高强度密码:由数字、小写字母、大写字母共同组成;
                                       超高强度密码:由数字、小写字母、大写字母、符号共同组成
                        """);
                  
               }
            }
         } else if (p == 1) {
            try {
               File file = new File("D:\\map.txt");
               if (file.exists() && file.isFile()) {
                  Scanner fileScanner = new Scanner(file);
                  while (fileScanner.hasNextLine()) {
                     String[] pair = fileScanner.nextLine().split(":");
                     if (pair.length == 3) {
                        map.put(pair[0], pair[1]);
                     }
                  }
                  fileScanner.close();
               }
            } catch (IOException e) {
               JOptionPane.showMessageDialog(null, "读取文件错误:" + e.getMessage());
               return;
            }
            String queryKey = JOptionPane.showInputDialog(null, "请输入查询密码的名称:");
            if (map.containsKey(queryKey)) {
               String updateTime = "";
               try {
                  File file = new File("D:\\map.txt");
                  Scanner fileScanner = new Scanner(file);
                  while (fileScanner.hasNextLine()) {
                     String[] pair = fileScanner.nextLine().split(":");
                     if (pair.length == 3 && pair[0].equals(queryKey)) {
                        updateTime = pair[2];
                        break;
                     }
                  }
                  fileScanner.close();
               } catch (IOException e) {
                  JOptionPane.showMessageDialog(null, "读取文件错误:" + e.getMessage());
                  
               }
               JOptionPane.showMessageDialog(null, "名称对应的密码为:" + map.get(queryKey) + "\n" + "最近一次更新时间为:" + updateTime + "\n" + "密码已自动复制到剪贴板");
               
               new write2(map.get(queryKey));
            } else {
               JOptionPane.showMessageDialog(null, "不存在此密码");
               
            }
         } else {
            JOptionPane.showMessageDialog(null, "输入错误");
         }
      } else if (u == 1) {
         JOptionPane.showMessageDialog(null, "<html" + "><h2" + "><font color='pink',size=6" + ">更新特性:<br></font><fontcolor='pink'," + "size=2>\n增加密码名称索引,方便查找密码\n" + "增加内部库,保证密码安全性\n" + "增加密码的更新时间" + "bug更新:修复了偶现的剪切板输入流错误\n修复了生成过程中偶现的密码符号的重叠");
      }
   }
   
   
   public static void write(String filepath, String content) throws IOException {
      BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filepath, true));
      bufferedWriter.write(content);
      bufferedWriter.close();
   }
   
   public static void mapWrite(String key, String value) {
      
      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String currentTime = dateFormat.format(new Date());
      try {
         FileWriter writer = new FileWriter("D:\\map.txt", true);
         writer.write(key + ":" + value + ":" + currentTime);
         writer.write(System.lineSeparator());
         writer.close();
         JOptionPane.showMessageDialog(null, "密码保存成功!");
         
      } catch (IOException e) {
         JOptionPane.showMessageDialog(null, "写入文件错误:" + e.getMessage());
      }
   }
}

class write2 {
   write2(String st1) {
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable txt = new StringSelection(st1);
      clipboard.setContents(txt, null);
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值