Advertisement
sidex15

java login system

Oct 1st, 2018
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.68 KB | None | 0 0
  1. import java.awt.event.*;
  2. import java.awt.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. import javax.swing.JOptionPane;
  6. import javax.swing.JWindow;
  7. import java.lang.*;
  8. import java.util.Scanner;
  9.  
  10. public class sa extends JFrame implements  ActionListener {
  11.     JButton b1;
  12.     JButton b3, b4;
  13.     Container con = getContentPane();
  14.     JPanel panel;
  15.     JLabel fu, ad, re, ren, reg, age;
  16.     JTextField ful, addr, ref, refn, agg;
  17.     JCheckBox c = new JCheckBox("Show Password");
  18.     Choice ch = new Choice();
  19.         CheckboxGroup gp = new CheckboxGroup();
  20.                 Checkbox male = new Checkbox("Male", gp, false);
  21.                     Checkbox female = new Checkbox("Female", gp, false);
  22.                         Checkbox other = new Checkbox("Other", gp, false);
  23.                             JLabel gender = new JLabel("Gender");
  24.                                             JPasswordField pass;
  25.                                             JButton b5, b6;
  26.                                             JTextField user;
  27.                                             JPasswordField ps, pw;
  28.                                             JTextField username;
  29.                                            
  30.     sa()
  31.     {
  32.         Scanner iput = new Scanner(System.in);
  33.         age = new JLabel("Age");
  34.                                 fu= new  JLabel("Enter Full Name");
  35.                                 ad= new JLabel("Enter Adress");
  36.                                 re= new JLabel("Who Refers you to join the company?");
  37.                                 ren= new JLabel("Enter Referral ID number");
  38.                                 ful= new JTextField(15);
  39.                                 ful.addActionListener(this);
  40.                                 addr= new JTextField(15);
  41.                                 addr.addActionListener(this);
  42.                                 ref = new JTextField(15);
  43.                                 refn = new JTextField(15);
  44.                                 reg = new JLabel("                       REGISTER                       ");
  45.                                 agg = new JTextField(10);
  46.                                            
  47.         //proceed button
  48.         b1 = new JButton("Proceed");
  49.         b1.setBackground(Color.GREEN);
  50.         //JButton Action
  51.         b1.addActionListener(this);
  52.         //Jpanel
  53.         panel = new JPanel();
  54.         con.setLayout(new BorderLayout());
  55.        
  56.        
  57.         //
  58.         panel.add(reg);
  59.         //full name
  60.         panel.add(fu);
  61.         panel.add(ful);
  62.         //address
  63.         panel.add(ad);
  64.         panel.add(addr);
  65.         //gender
  66.         panel.add(gender);
  67.         panel.add(male);
  68.         panel.add(female);
  69.         panel.add(other);
  70.         //age
  71.         panel.add(age);
  72.         panel.add(agg);
  73.         //referral
  74.         panel.add(re);
  75.         panel.add(ref);
  76.         //
  77.         panel.add(ren);
  78.         panel.add(refn);
  79.        
  80.        
  81.        
  82.        
  83.        
  84.        
  85.        
  86.        
  87.        
  88.         //button
  89.         panel.add(b1);
  90.        
  91.         con.add(panel);
  92.         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  93.     }
  94.     public void actionPerformed(ActionEvent e){
  95.         Object source = e.getSource();
  96.         String fname=ful.getText();
  97.         String nn=addr.getText();
  98.         String nnn=ref.getText();
  99.         String nmn=refn.getText();
  100.         String agr=agg.getText();
  101.         if(source==b1){
  102.         if(fname.isEmpty()){
  103.             JOptionPane.showMessageDialog(null, "You didn't enter your name");
  104.            
  105.         }
  106.         else if(nn.isEmpty()){
  107.             JOptionPane.showMessageDialog(null, "Please enter your address");
  108.         }
  109.         else if(agr.isEmpty()){
  110.             JOptionPane.showMessageDialog(null, "Please Verify Age");
  111.         }
  112.         else if(nnn.isEmpty()){
  113.             JOptionPane.showMessageDialog(null, "Please fill refferal's name");
  114.         }
  115.         else if(nmn.isEmpty()){
  116.             JOptionPane.showMessageDialog(null, "Please enter referral's ID number");
  117.         }
  118.         else{
  119.             JFrame frame;
  120.             JPanel pan;
  121.             JLabel l, lp, lpr;
  122.             Checkbox ch;
  123.            
  124.             frame = new JFrame("Acct Fill up");
  125.             frame.setVisible(true);
  126.             frame.setBounds(450, 100, 175, 275);
  127.             frame.setVisible(true);
  128.             frame.setResizable(false);
  129.            
  130.                 pan = new JPanel();
  131.                    
  132.                     l = new JLabel("Enter User ID");
  133.                     lp = new JLabel("Enter Password");
  134.                     lpr = new JLabel("Verify Password");
  135.                     user = new JTextField(10);
  136.                     ps = new JPasswordField(10);
  137.                     pw = new JPasswordField(10);
  138.                     b3 = new JButton("Register");
  139.                     b4 = new JButton("Cancel");
  140.             //username
  141.             pan.add(l);
  142.             pan.add(user);
  143.             //password
  144.             pan.add(lp);
  145.             pan.add(ps);
  146.             //verify
  147.             pan.add(lpr);
  148.             pan.add(pw);
  149.            
  150.            
  151.             pan.add(b3);
  152.             b3.setBackground(Color.ORANGE);
  153.             pan.add(b4);
  154.             b4.setBackground(Color.RED);
  155.             b4.addActionListener(this);
  156.             frame.add(pan);
  157.             Object src = e.getSource();
  158.             b3.addActionListener(this);
  159.         }  
  160.         }
  161.         String us = user.getText();
  162.         String zx = ps.getText();
  163.         String cx= pw.getText();
  164.         String cv = ps.getText();
  165.         String vc = pw.getText();
  166.         int length = 0;
  167.         int numCount = 0;
  168.         int capCount = 0;
  169.         int x;
  170.         String result;
  171.        
  172.            
  173.        
  174.          if(source==b3){
  175.             if(us.isEmpty()){
  176.             JOptionPane.showMessageDialog(null,"Please Confirm User ID");
  177.         }
  178.         else if(zx.isEmpty()){
  179.             JOptionPane.showMessageDialog(null, "Please Enter Password");
  180.         }
  181.         for(x=0; x<cv.length(); x++){
  182.             if(cv.charAt(x)>=47 && cv.charAt(x)<=58 || (cv.charAt(x) >= 65 && cv.charAt(x)<=91) || (cv.charAt(x)>=97 && cv.charAt(x) <= 122)){ 
  183.             }
  184.             else{
  185.                 JOptionPane.showMessageDialog(null, "Please make stronger password");
  186.             }
  187.             if((cv.charAt(x) > 47 && cv.charAt(x) < 58)){
  188.                 numCount++;
  189.             }
  190.            
  191.             if((cv.charAt(x) > 64 && cv.charAt(x)<91)){
  192.                 capCount++;
  193.             }
  194.             length = (x+1);
  195.         }
  196.         if(numCount < 2){
  197.             JOptionPane.showMessageDialog(null, "Not enough Numbers in password");
  198.         }
  199.         else if(capCount < 2){
  200.             JOptionPane.showMessageDialog(null, "Not enough Capital letters in password");
  201.         }
  202.         else if(length < 8){
  203.             JOptionPane.showMessageDialog(null, "Password too short, Please make Stronger Password");
  204.             JOptionPane.showMessageDialog(null, "must be atleast 8 characters long");
  205.         }
  206.        
  207.         else if(cx.isEmpty()){
  208.             JOptionPane.showMessageDialog(null, "Please Verify your Password");
  209.         }
  210.         //your problem...
  211.         else if(cx!=zx){
  212.             JOptionPane.showMessageDialog(null, "Please Verify your Password");
  213.         }
  214.         else{
  215.             JOptionPane.showMessageDialog(null, "Registered Successfully!");
  216.             JOptionPane.showConfirmDialog(null, "Do you want to login now?");
  217.  
  218.             JWindow window = new JWindow();
  219.             window.getContentPane().add(new JLabel("", new ImageIcon("3.png"),SwingConstants.CENTER));
  220.             window.setBounds(450, 100, 320, 240);
  221.             window.setSize(650,400);
  222.             window.setVisible(true);
  223.             try{
  224.             Thread.sleep(5000);
  225.             }
  226.             catch(InterruptedException ex){}
  227.             window.dispose();
  228.        
  229.            
  230.             JFrame frame = new JFrame("Login");
  231.             frame.setVisible(true);
  232.             frame.setBounds(450, 100, 185,265);
  233.             frame.setResizable(false);
  234.             JLabel l, la;
  235.            
  236.             l = new JLabel("UserID");
  237.             la = new JLabel("Password");
  238.             JPanel p =new JPanel();
  239.            
  240.            
  241.  
  242.                
  243.                 user = new JTextField(15);
  244.                     pass = new JPasswordField(15);
  245.                         pass.setEchoChar('•');
  246.                             pass.addActionListener(this);
  247.                                 user.addActionListener(this);
  248.                                
  249.                                 b5 = new JButton("Login");
  250.                                     b6 = new JButton("Cancel");
  251.                                     b5.addActionListener(this);
  252.                                     b5.addActionListener(this);
  253.                                    
  254.                        
  255.                 p = new JPanel();
  256.                         //loigin
  257.                         p.add(l);
  258.                         p.add(user);
  259.                         p.add(la);
  260.                         p.add(pass);
  261.                         p.add(c);
  262.            
  263.                         p.add(b5);
  264.                         p.add(b6);
  265.                         b5.setBackground(Color.GREEN);
  266.                         b6.setBackground(Color.ORANGE);
  267.                         frame.add(p);
  268.                         c.addActionListener(this);
  269.                         b5.addActionListener(this);
  270.                         b6.addActionListener(this);
  271.                 }
  272.         }
  273.         if(source==b5){
  274.             String uname=user.getText();
  275.             String psd=pass.getText();
  276.             String meme=user.getText();
  277.             String memee=pass.getText();
  278.            
  279.                 String userr=user.getText();
  280.                 String passw=ps.getText();
  281.                 String passs=pw.getText(); 
  282.                     String name=ful.getText();     
  283.             if(uname.equals(userr) && psd.equals(passw) && psd.equals(passs)){
  284.                 JOptionPane.showMessageDialog(null, "Welcome " + name + "!");
  285.                 JFrame f1;
  286.                 f1 = new JFrame("WELCOME!");
  287.                 f1.setVisible(true);
  288.                 f1.setSize(5000,5000);
  289.                 f1.setResizable(false);
  290.             }
  291.             else if(meme.equals("Administrator") && memee.equals("123")){
  292.                 JOptionPane.showMessageDialog(null, "Welcome back Admin");
  293.                 JButton bn;
  294.                     JFrame f2;
  295.                     JLabel la,al;
  296.                     f2 = new JFrame("WELCOME!");
  297.                     f2.setVisible(true);
  298.                     f2.setSize(5000,5000);
  299.                     f2.setResizable(false);
  300.                     la = new JLabel("Administrator", SwingConstants.CENTER);
  301.                     f2.add(la);
  302.             }
  303.             else{
  304.                 JOptionPane.showMessageDialog(null, "Invalid Username or Password");
  305.             }
  306.            
  307.         }
  308.         else if(source==b6){
  309.             System.exit(0);
  310.         }
  311.        
  312.         else if(source==b4){
  313.             System.exit(0);
  314.         }
  315.         else{
  316.         }
  317.         if(c.isSelected()){
  318.                     pass.setEchoChar((char)0);
  319.                 }
  320.                 else{
  321.                     pass.setEchoChar('•');
  322.                 }
  323.  
  324.        
  325.     }
  326.     public static void main(String[]args){
  327.         JWindow window = new JWindow();
  328.         window.getContentPane().add(new JLabel(" ", new ImageIcon("3.png"),SwingConstants.CENTER));
  329.         window.setBounds(450, 100, 320, 240);
  330.         window.setSize(600,398);
  331.         window.setVisible(true);
  332.         try{
  333.             Thread.sleep(0);
  334.         }
  335.         catch(InterruptedException e){}
  336.         window.dispose();
  337.        
  338.         sa frm = new sa();
  339.         frm.setVisible(true);
  340.         frm.setResizable(false);
  341.         frm.setTitle("Aim Global");
  342.         frm.setBounds(500,150,222,375);
  343.         //END
  344.     }
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement