Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java registration login study notes

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Import java.util.Scanner

/ / user class

Class Users

{

String username

String password

Public Users (String username,String password) {

This.username = username

This.password = password

}

}

Public class LoginDome {

Users user

/ / determine the user name and password

Public boolean userLogin (String username,String password)

{

If (this.user.username.equals (username) & & this.user.password.equals (password))

{

Return true

}

Else

{

Return false

}

}

Public void setUser (Users user)

{

This.user = user

Public static void main (String [] args) {

String username

String password

Int iCount = 0; / / counter determines how many times to log in

Boolean flag = false;// to determine whether the login is successful or not

Scanner in = new Scanner (System.in)

System.out.println ("* user registration *")

System.out.println ("Please enter user name:")

Username = in.nextLine ()

System.out.println ("Please enter password:")

Password = in.nextLine ()

/ / keep the entered user and password

Users u = new Users (username,password)

LoginDome demo = new LoginDome ()

Demo.setUser (u)

System.out.println ("Registration successful!")

System.out.println ("* user login *")

Do {

System.out.println ("Please enter user name:")

Username = in.nextLine ()

System.out.println ("Please enter password:")

Password = in.nextLine ()

If (demo.userLogin (username,password)) / / call the method to determine whether the login is successful or not

{

Break

}

Else

{

ICount + +; / / number of records

If (iCount > = 3 & & flag = = false) / / if login fails more than 3 times

{

System.out.print ("if the login fails more than three times, the program will exit!")

System.exit (0)

}

Else

{

System.out.println ("Please check username and password")

}

}

} while (true)

}

}

* user registration *

Please enter a user name:

Liwen

Please enter your password:

123456

Registered successfully!

* user login *

Please enter a user name:

Li

Please enter your password:

two hundred and twenty two

Please check your user name and password

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report