Java Login Verification Code problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.