User login and register system (error 3 times freeze accounts)

 

package Aaa;
/*
 * 封装账号密码手机号
 */

public class Login {
    private String zhangHao;
    private String password;
    private String phone;
    public String getZhangHao() {
        return zhangHao;
    }
    public void setZhangHao(String zhangHao) {
        this.zhangHao = zhangHao;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public Login(String zhangHao,String password,String phone) {
        super();
        
        this.zhangHao= zhangHao;
        this.password= password;
        this.phone = phone ;
    }
    
    
}
package Aaa;

import java.util.HashMap;
import java.util.Scanner;

public class LoginTest {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        Login user1 = new Login("123456","zzz123", "18312345677");
        Login user2 = new Login("654321","hhh123","18789530972");
        Login user3 = new Login("666666","kkk123","18789530973");
        HashMap<String,Login> map = new HashMap<>();
        map.put( user1.getZhangHao(), user1);
        map.put( user2.getZhangHao(), user2);
        map.put( user3.getZhangHao(), user3);
        System.out.println("************欢迎进入系统********************");
        System.out.println ( " Please select: 1 2. Log Register.    " ); 
        String Change = sc.next (); 
        
        Switch (Change) {
         Case  " 1 " :
             int Z = 0 ;
             the while ( to true ) { 
                the System. OUT .println ( " Please enter the account number: " ); 
                String zhangHao = sc.next (); 
                System. OUT .println ( " Please enter your password: " ); 
                String password= Sc.next (); 
                
                IF (. Map.containsKey (zhangHao) && the Map GET . (ZhangHao) .getPassword () the equals (password)) { 
                    . System OUT .println ( " Login successful !! Loading system ... " );
                     BREAK ; 
                } the else  IF !. (map.containsKey (zhangHao) && the Map GET (zhangHao) .getPassword () the equals (password)) {. 
                    System. OUT .println ( " wrong password (3 times will freeze the account! !!) " ); 
                    Z + = . 1 ; 
                    
                    IF (Z == 2 ) {
                        System. OUT .println ( " 've mistake twice !! You only have one chance! " ); 
                        
                    } 
                    IF (z> = 3 ) { 
                        . System OUT .println ( " wrong password three times, the account has been frozen !! !!!!!!!! " );
                         BREAK ; 
                    } 
                      
                    } the else { 
                        the System. OUT .println ( " account does not exist, please re-enter " ); 
                } 
                
            } 
            BREAK ; 
           
        Case  "2 " : 
            . System OUT .println ( " Please enter your registration account: " ); 
            String addAccount = sc.next ();
             IF (map.containsKey (addAccount)) { 
                System. OUT .println ( " account already exists, registration failed ! " );
                 BREAK ; 
            } the else { 
                . System OUT .println ( " Please enter the registration password: " ); 
                String addPassword = sc.next (); 
                System.OUT .println ( " Please enter the registration password again: " ); 
                String addPassword2 = sc.next (); 
                System. OUT .println ( " Please enter the phone number: " ); 
                String addphone = sc.next ();
                 IF (addPassword2 .equals (addPassword)) { 
                    System. OUT .println ( " registered successfully! " ); 
                    System. OUT .println ( " your login account is: " + addAccount + " , login password: "AddPassword + + " , the phone number is: " + addphone); 
                } the else { 
                    System. OUT .println ( " password input error, registration failed! " ); 
                } 
                
            } 
            BREAK ;
         default : 
            . System OUT .println ( " choosing the wrong exit! system! " ); 
            
        
    } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/hxtzzz/p/11277160.html