Java将密码框中没输入密码是显示为请输入密码输入密码是显示星号
Java密码扩展(The Java Cyptogaphy Extension),是JDK1.4的一个重要部分,基本上,他是由一些包构成的,这些包形成了一个框架并实现了一些加密,密钥生成算法和协议,消息认证码等算法,这篇文章将想你介绍JCE的安装和使用。
值得注意的是,尽管JCE是JDK1.4的核心包的一部分,我们将首先用JDK1.2及高一点的版本向你演示一下如果安装配置JCE(静态安装)。
稍后,将向你介绍如何在不安装的情况下使用JCE(动态安装)。
最后,将演示怎么生成密钥和密码,及如果进行基本的加密.解密。
提供者是什么? 提供者是特定加密算法的实现者,有的提供者(提供的加密技术)是免费的,有的不免费,IBM, Bouncy Castle, 和 RSA都是一些(加密)提供者.在本文的后面,我们将考察一下来自Bouncy Castle的RSA算法。
Sun 也向大家说明了如果实现自己的提供者(需要符合jDK的一些约定)。
静态安装 在安装和使用JCE之前,你需要从 Sun We site(这里是以暗中sun的提供者为例).获得他的安装包,JCE有sun他自己的安全提供者-sunJCE,为了吧sunJCE静态的安装到默认的提供者列表中,你需要修改安全属性文件:? \je\li\secuity\java.secuity (Win32) ? jelisecuityjava.secuity (UNIX)如果你把JDK安装在C:\jdk1.3,你需要编辑以下文件:C:\jdk1.3\je\li\secuity\java.secuity 为了安装SunJCE,你需要在以上文件中加入:secuity.povide.n=com.sun.cypto.povide.SunJCE把n用你加入的提供者的优先级代替(注意:序号要保持递增,不能跳过,但可以调整前后顺序)。
Listing A 用于查看你安装过的提供者的信息,结果在Listing B中列出,显示提供者的能力,比如说可用的加密算法。
Listing A: PovideInfomation.javaimpot java.secuity.Povide;impot java.secuity.Secuity;impot java.util.Set;impot java.util.Iteato;pulic class PovideInfomation { pulic static void main(Sting[] ags) { Povide[] povides = Secuity.getPovides(); fo (int i = 0; i povides.length; i++) { Povide povide = povides[i]; System.out.pintln("Povide name: " + povide.getName()); System.out.pintln("Povide infomation: " + povide.getInfo()); System.out.pintln("Povide vesion: " + povide.getVesion()); Set enties = povide.entySet(); Iteato iteato = enties.iteato(); while (iteato.hasNext()) { System.out.pintln("Popety enty: " + iteato.next()); } } }}
java密码代码
public class EncryptionFormVI{static Scanner scan = new Scanner(System.in);public static int menu(){ //displaysthe menu and returns the user's choiceSystem.out.println("Encryption/Decoder");System.out.println("1. Encrypt");System.out.println("2. Decode");System.out.println("3. Quit");System.out.print("Your choice: ");int yourPick =scan.nextInt();String buffer=scan.nextLine(); //clears thebuffer of the leftover enter characterSystem.out.println();return yourPick;}public static String getMessage(){ //user enters the message that will beencrypted or decodedSystem.out.print("Enter message: ");String message= scan.nextLine();return message;}public static String code(String line){ //returns the line that has been coded byshifting the characters a given distanceString newMessage = getMessage();for (int i=0;i<line.length();i++){newMessage= newMessage + (char)(line.charAt(i));}return newMessage ;}public static void encrypt(){ // gets a message that is then encrypted anddisplayedString original = "";System.out.println("Encrypted message: " + code(original));System.out.println();}public static void decode(){ //gets an encrypted message and decodes anddisplays the original textString encrypted = getMessage(); System.out.println("Original message: " + code(encrypted));System.out.println();}public static void main(String[] args){int choice = menu();while (choice!= 3){switch(choice){case 1:encrypt();break;case 2:decode();break;default:System.out.println("error");}choice = 3;}}}
java密码文本框的选用
JAVA的API帮助文档在JTextField中写到setEchoChar 和 getEchoChar 方法不是直接提供的,以避免可插入的外观的新实现意外公开密码字符。
为了提供类似密码的服务,单独的类 JPasswordField 扩展了 JTextField,从而通过可插入外观独立地提供此服务。
JPasswordField是继承JTextField,在JTextField中没找到你说的setEchoChar 和getEchoChar 方法 。
但这两个方法是在JpasswordField中实现的。
密码框为密码的安全性考虑很多,如复制的处理之类的。
。
。
所以一般还是建议使用JPasswordField。
参考JDK1.6
如何使用java对密码加密 加密方式aes
import java.awt.*;import java.awt.event.*;public class TestPassword {public static void main(String[]args) {MyTestFrame mf = new MyTestFrame("密码输入");}}class MyTestFrame extends Frame {Button b = new Button("确认");TextField tf = new TextField(15);public MyTestFrame(String str){super(str);tf.setEchoChar('*');Panel p = new Panel();p.setBackground(Color.BLACK);b.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String str = tf.getText();// System.out.println(str);if(str.length()System.out.println("输入不能少于八位");tf.setText("");}else {if(str.matches("\\d*")) {System.out.println("密码强度低 ");}if(str.matches("[a-z0-9]*")){System.out.println("密码强度中 ");}if(str.matches("[a-zA-Z0-9]*")) {System.out.println("密码强度高");}}}});this.setLayout(new BorderLayout());p.add(tf);this.add(b,BorderLayout.EAST);this.add(p,BorderLayout.CENTER);pack();this.setVisible(true);this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});}}可费劲了 把课本又翻了一遍,正则表达式又复习了一下,gui也用上了
java:实现一个简单的注册系统
1、验证字符串长度,可以使用字符串的length方法;2、字符串的equals方法可以验证字符序列是否相等;3、更为复杂的验证,譬如验证数字,可以使用正则表达式。
public boolean checkUsername(String username) {return null != username && !"".equals(username) && username.length() >= 6;}public boolean checkPassword(String password) {return checkUsername(password) && password.matches("^[-\\+]?[\\d]*$");}public static void main(String[] args) {Register register = new Register();System.out.println("没有账号?快速注册\n请输入用户名,按Enter键确认");Scanner sc = new Scanner(System.in);String username = "";while (true) {username = sc.nextLine();if (register.checkUsername(username)) {break;} else {System.out.println("用户名长度不符,请输入正确的用户名");}}System.out.println("请输入密码,按Enter键确认");String password = "";while (true) {password = sc.nextLine();if (register.checkPassword(password)) {break;} else {System.out.println("密码长度不符,请输入正确的密码");}}System.out.println("为了确保正确,请再次输入密码");String repassword = "";while (true) {repassword = sc.nextLine();if (!register.checkPassword(repassword)) {System.out.println("密码长度不符,请输入正确的密码");} else if (!repassword.equals(password)) {System.out.println("两次密码输入不一致,请输入相同的密码");} else if (register.checkPassword(repassword) && repassword.equals(password)) {break;}}System.out.println("注册成功,正在前往登录页面...");}
java 问题oauth2的password
目的是你所提到的解决Code授权码的问题或者会所前面所提到的拿到对方给各自的access_token的过程;service_a类似.服务器的思路可以简单的对services的authorizationrequest简单check一下IP之类的.如果真要用完整的oauth/.对于service_b->,不用太复杂即,service_a->service_b的话,request_credential_of_service_a=digest(request+access_token_of_service_b)然后在service_b端的话,重新计算一下digest(request+access_token_of_service_b)是否跟request_credential_of_service_a一致就行了.一致则认为确实是service_a发送的请求;oauth2的话,可能需要对services内嵌oauthserver或者假设一个中立的authorizeserver.这个是oauth标准流程必须的.结论就是,1.考虑如何分享/,然后就直接返回对应的access_token就好了
java GUI
你的问题全有三处,1:监听那样用好像不行,最好弄个内部类 2:你的那个nameinput,passwordinput定义了两次 (JTextField nameinput,passwordinput; final JTextField nameinput=new JTextField(15); final JTextField passwordinput=new JTextField(15); ) 3:e.getSource()这个方法具体的我也不太懂不过你用 System.out.println(e.getSource());打印出来肯定 不是OK 对象我把它了加了一个(String st = e.getActionCommand(); if (st.equals("登录")){})这样就可以了我改的原码是:import javax.swing.*;import java.awt.*;import java.awt.event.*;public class HelloWorld extends JPanel { static final int WIDTH = 300; static final int HEIGHT = 150; JFrame mainJFrame; JTextField nameinput, passwordinput; JButton ok, cancel; public void add(Component c, GridBagConstraints constraints, int x, int y, int w, int h) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = w; constraints.gridheight = h; add(c, constraints); } public HelloWorld() { mainJFrame = new JFrame(); mainJFrame.setTitle("欢迎进入java世界"); setLayout(new GridBagLayout()); mainJFrame.add(this, BorderLayout.WEST); mainJFrame.setSize(WIDTH, HEIGHT); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int width = screenSize.width; int height = screenSize.height; int x = (width - WIDTH) / 2; int y = (height - HEIGHT) / 2; mainJFrame.setLocation(x, y); // final JPasswordField passwordinput=new JPasswordField(15); nameinput = new JTextField(15); passwordinput = new JTextField(15); JButton ok = new JButton("登录"); // ok.setActionCommand("pp"); SS s = new SS(); ok.addActionListener(s); JButton cancel = new JButton("取消"); cancel.addActionListener(s); JLabel title = new JLabel("欢迎进入java世界"); JLabel name = new JLabel("用户名"); JLabel password = new JLabel("密 码"); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.EAST; constraints.weightx = 3; constraints.weighty = 4; add(title, constraints, 0, 0, 4, 1); add(name, constraints, 0, 1, 1, 1); add(password, constraints, 0, 2, 1, 1); add(nameinput, constraints, 2, 1, 1, 1); add(passwordinput, constraints, 2, 2, 1, 1); add(ok, constraints, 1, 3, 1, 1); add(cancel, constraints, 2, 3, 1, 1); mainJFrame.setVisible(true); mainJFrame.setResizable(false); mainJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new HelloWorld(); } class SS implements ActionListener { public void actionPerformed(ActionEvent e) { String st = e.getActionCommand(); System.out.println(st); System.out.println(e.getSource()); if (st.equals("登录")) { String nametext = nameinput.getText(); String passwordtext = passwordinput.getText(); String str = new String(passwordtext); boolean x = (nametext.equals("ligang")); boolean y = (str.equals("07057516")); boolean z = (x && y); if (z == true) { mainJFrame.dispose(); mainJFrame.setVisible(false); } else { nameinput.setText(" "); passwordinput.setText(" "); JOptionPane.showMessageDialog(new HelloWorld(), "输入有误!"); } } else if (st.equals("取消")) { nameinput.setText(" "); passwordinput.setText(" "); } } }}希望你能采纳!
转载请注明出处51数据库 » java Jassword