Program Design Ideas
Randomly generates a 6-bit string
Read the user input information, including the account password.
Verify that the verification code entered by the user is the same as the resulting random string.
If it's not the same, prompt and return to the re-entry interface.
If the same words will prompt the login success, and refresh the verification code to facilitate the next user's use.
Program Flowchart
Program source Code
Import Java.awt.color;import java.awt.component;public static void Main (string[] args) {//TODO auto-generated method stub JFrame frame= New JFrame ("Landing test"); Frame.setbounds ($, +), frame.setsize (350,200); Frame.setdefaultcloseoperation ( Jframe.exit_on_close); Panel panel=new Panel (), Frame.add (panel);p lacecompoents (panel);p Anel.setbackground (Color.light_gray); Frame.setvisible (TRUE);} private static void Placecompoents (panel panel) {//TODO auto-generated method stub panel.setlayout (null);//Name information JLabel userlabel=new JLa Bel ("User"); Userlabel.setbounds (Userlabel),;p Anel.add; JTextField usertext=new JTextField (165), Usertext.setbounds (+, Anel.add,;p usertext);//password Information JLabel Passwordlabel=new JLabel ("password");p asswordlabel.setbounds ((),;p Anel.add (Passwordlabel); JPasswordField passwordtext=new JPasswordField ();p asswordtext.setbounds (+, 165);p Anel.add (PasswordText) ;//Authentication code information string Code= ""; for (int i=0;i<6;i++) {int intval= (int) (Math.random () *26+97); CoDe=code+ (char) intval; }string Codex=code; JLabel ident=new JLabel (code) ident.setbounds (n, N, a);p Anel.add (ident);//captcha text field JLabel codes=new JLabel (" Codes "); Codes.setbounds (ten, Anel.add, and,);p (codes); JTextField codetext=new JTextField (6); Codetext.setbounds (n, A, a);p Anel.add (codetext);//Button JButton Loginbutton=new JButton ("login"); Loginbutton.setbounds (+, +),;p anel.add (Loginbutton); Loginbutton.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {String c=codetext. GetText (); String U=usertext.gettext (); Char[] P1=passwordtext.getpassword (); String p= ""; P=p.valueof (p1); if (C.equals (Codex)) {Joptionpane.showmessagedialog (null, "Hello" +u+ ", welcome!) Wish you a pleasant day "); Usertext.settext ("Your mother called You Home for dinner"); Passwordtext.settext (""); Codetext.settext (""); String code= ""; for (int i=0;i<6;i++) {int intval= (int) (Math.random () *26+97); Code=code+ (char) intval; } String Codex=code; Ident.settext (codex); } else {joptionpane.showmessagedialog (null, "Authenticode error"); } } } ); JButton exit=new JButton ("exit"); Exit.addactionlistener (new ActionListener () {public void actionperformed ( ActionEvent e) {system.exit (0); }); Exit.setbounds (+, +, +);p anel.add (exit);}}
Program run
Java Login Verification Code problem