In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use Java to achieve an authentication server login system", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Java to achieve an authentication server login system" article.
I. Preface
The code is all written by myself, and the author is a rookie. Please forgive me. If there is anything wrong with the code, you can point out the problem.
Writing such a simple login alone is because it is more convenient. Because I have tried many times to write this login system test directly in the written program, it is very troublesome and inconvenient, so I wrote this set of code alone. Personally, I think it's much more convenient to put the written program into it and modify it.
Log in to the system server import java.io.*;import java.net.ServerSocket;import java.net.Socket;public class ServerLogin {public static void main (String [] args) throws IOException {Server ();} public static void Server () throws IOException {String name = "AccountPassword.txt"; String path = System.getProperty ("user.dir") + "\" + name; File file = new File (path) If (! file.exists ()) {BufferedWriter bw = new BufferedWriter (new FileWriter (file.getAbsoluteFile (); file.createNewFile (); bw.write ("1391634154); bw.newLine (); bw.write (" 654321); bw.flush (); bw.close () System.out.println ("Server generates account data");} ServerSocket server = new ServerSocket (8848); System.out.println ("Port opened successfully"); Object obj = new Object (); while (true) {Socket accept = server.accept () New Thread (new Runnable () {@ Override public void run () {int A = 0; boolean ServerStart = false; boolean WhileThread = true; int len = 0; try {InputStream inputStream = accept.getInputStream ()) OutputStream outputStream = accept.getOutputStream (); while (WhileThread) {if (ServerStart==false) {System.out.println ("Server=false has been executed"); BufferedReader br = new BufferedReader (new FileReader (file.getAbsoluteFile () Byte [] bytes = new byte [1024]; len = inputStream.read (bytes); String User = new String (bytes,0,len); len = 0; String Line While ((Line = br.readLine ())! = null) {if (Line.equals (User)) {System.out.println ("correct" + Thread.currentThread () .getName () + "- > User:" + User) OutputStream.write ("true" .getBytes ()); ServerStart = true; break } if (! Line.equals (User)) {System.out.println ("failure" + Thread.currentThread (). GetName () + "- > User:" + User) OutputStream.write ("false" .getBytes ()); break } if (alternate 3) {/ / end cycle disconnect WhileThread = false InputStream.close (); outputStream.close (); accept.close () } catch (IOException e) {}) .start ();} III. Log in to the system client import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.Socket;import java.util.Scanner Public class ClienteLogin {static Scanner sc = new Scanner (System.in); static String Server = "false"; public static void main (String [] args) throws IOException {Cliente ();} public static void Cliente () throws IOException {int ClienteOff = 0; System.out.println ("ClienteOn"); System.out.print ("IP:"); String next = sc.next () System.out.print ("Port:"); int Port = sc.nextInt (); Socket socket = new Socket (next,Port); InputStream inputStream = socket.getInputStream (); OutputStream outputStream = socket.getOutputStream (); byte [] bytes = new byte [1024]; while (true) {if (ClienteOff = = 3) {break;} ClienteOff++ If (Server.equals ("false")) {System.out.print ("account:"); String User = sc.next (); System.out.print ("password:"); String Password = sc.next (); String AccountPassword = User+ "-" + Password; outputStream.write (AccountPassword.getBytes ()) Int len = inputStream.read (bytes); Server = new String (bytes,0,len); len = 0; if (Server.equals ("false")) {System.out.println ("login failed, account or password error") } else if (Server.equals ("true")) {System.out.println ("login successful") } the above is about the content of this article on "how to use Java to implement an authentication server login system". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.