关于getPassword用法 API中的getText()方法已过时,谁能举例说明一下关于getPassword()用法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private static boolean isPasswordCorrect(char[] input) { boolean isCorrect = true; char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' }; if (input.length != correctPassword.length) { isCorrect = false; } else { isCorrect = Arrays.equals (input, correctPassword); } //Zero out the password. Arrays.fill(correctPassword,'0'); return isCorrect; }public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (OK.equals(cmd)) { //Process the password. char[] input = passwordField.getPassword(); if (isPasswordCorrect(input)) { JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password."); } else { JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message", JOptionPane.ERROR_MESSAGE); } //Zero out the possible password, for security. Arrays.fill(input, '0'); passwordField.selectAll(); resetFocus(); } else ...//handle the Help button...} String.valueOf(passwordField.getPassword()) ==getText() getPassword() 是返回一个char[];为什么要求不用getText() 而要用getPassword()呢, 这是从安全性方面的考虑, 你得到这个char[]并使用以后,需要立即向这个char[]中填0, 毁尸灭迹; 这样系统中就没有保存密码的明文了, 这样就安全了;安全的用法是://JPasswordField p=new JPasswordField();char[] password=p.getPassword();//... 在这里使用密码Arrays.fill(password,'\0');如果不讲究,就直接这样用//JPasswordField p=new JPasswordField();String password=new String(p.getPassword()); 为什么放心?public static String valueOf(char data[]) { return new String(data);} java 宠物猫,有自己的代码,帮忙改一下,谢谢!! java重写的table位置问题 学着学着,就迷糊了!!请高手指点方向。。 怎样在java程序中控制内存的使用,比如一个程序要用大量的内存,怎么控制 小妹请教JSP编程高手,紧急紧急!! java 动态数组的问题 如何在java程序中获取当前程序所在的目录?高分 求高手点拨一个“Swing技术的”IM系统的“刷新好友列表”的工程实现方案. 一个简单问题,给分! jTextField 的输入问题?swing高手请进. 如何正则表达式替换url Java swing 使用substance后怎么改变颜色?
boolean isCorrect = true;
char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' }; if (input.length != correctPassword.length) {
isCorrect = false;
} else {
isCorrect = Arrays.equals (input, correctPassword);
} //Zero out the password.
Arrays.fill(correctPassword,'0'); return isCorrect;
}public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand(); if (OK.equals(cmd)) { //Process the password.
char[] input = passwordField.getPassword();
if (isPasswordCorrect(input)) {
JOptionPane.showMessageDialog(controllingFrame,
"Success! You typed the right password.");
} else {
JOptionPane.showMessageDialog(controllingFrame,
"Invalid password. Try again.",
"Error Message",
JOptionPane.ERROR_MESSAGE);
} //Zero out the possible password, for security.
Arrays.fill(input, '0'); passwordField.selectAll();
resetFocus();
} else ...//handle the Help button...
}
为什么要求不用getText() 而要用getPassword()呢, 这是从安全性方面的考虑, 你得到这个char[]并使用以后,需要立即向这个char[]中填0, 毁尸灭迹; 这样系统中就没有保存密码的明文了, 这样就安全了;
安全的用法是://JPasswordField p=new JPasswordField();
char[] password=p.getPassword();
//... 在这里使用密码
Arrays.fill(password,'\0');如果不讲究,就直接这样用//JPasswordField p=new JPasswordField();
String password=new String(p.getPassword());
return new String(data);
}