KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echoserver > EchoServerAuthenticator


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package echoserver;
16
17 import org.quickserver.net.server.*;
18 import java.io.*;
19 import org.quickserver.net.AppException;
20
21 public class EchoServerAuthenticator extends ServerAuthenticator {
22
23     public boolean askAuthorisation() throws IOException, AppException {
24         pout.println("User Name :");
25         username=in.readLine();
26         if(username==null) {
27             throw new IOException("Lost Connection");
28             //throw new AppException("Lost Connection");
29
}
30
31         pout.println("Password :");
32         password=in.readLine();
33         if(password ==null) {
34             throw new IOException("Lost Connection");
35             //throw new AppException("Lost Connection");
36
}
37         
38         if(username.equals(password)) {
39             pout.println("Auth OK");
40             return true;
41         } else {
42             pout.println("Auth Failed");
43             return false;
44         }
45     }
46 }
47
Popular Tags