Developers 4 Fun
Login for a fine experience !

Developers 4 Fun

This is a forum for all developers (begginers or experts).If you know how to program java, make a thread with tutorials.If you don`t know something ask,don`t be shy ! :P Have a problem?PM Admin
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share | 
 

 Java Login System

View previous topic View next topic Go down 
AuthorMessage
Admin
Admin


Posts: 3
Join date: 2011-06-21
Age: 24
Location: ~ On my lappy ~

PostSubject: Java Login System   Wed Jun 29, 2011 7:05 am

import java.util.Scanner;

class login {
public static void main(String args[]){
Scanner luci = new Scanner(System.in);
String idInput;
System.out.println("Please type ID: ");
idInput = luci.nextLine();
String passwordInput;
System.out.print("Please type Password: ");
passwordInput = luci.nextLine();


if(passwordInput.equals("enter password here") && (idInput.equals("enter id here"))){

System.out.println("Authentification complete!");

}else{
System.out.println("Rong ID or Password!");


}
}
}


Note:This program can only have 1 user and only 1.The idd and password can have numbers and an unlimited number of character.It can contain question mark...Basically anything on the keyboard....
Back to top Go down
View user profile http://developers4fun.american-forum.net
MaliPrinc



Posts: 1
Join date: 2011-12-09

PostSubject: Re: Java Login System   Fri Dec 09, 2011 3:02 am

Can you help me please?? I watched your tutorial but I still don't understand
I have code for Server,Client and ClientThread !

Code for Server:

import java.io.*;
import java.net.*;

public class ChatServer{


static KlijentNit klijenti[] = new KlijentNit[10];

public static void main(String args[]) {

int port = 2222;
if(args.length>0)port = Integer.parseInt(args[0]);
Socket clientSocket = null;
try {

ServerSocket serverSocket = new ServerSocket(port);
while(true){
clientSocket = serverSocket.accept();
for(int i=0; i<=klijenti.length; i++){
if(klijenti==null)
{

klijenti = new KlijentNit(clientSocket, klijenti);
klijenti.start();
break;
}


}
}
}
catch (IOException e) {
System.out.println(e);
}
}
}

Code for Client:

import java.io.*;
import java.net.*;

static Socket clientSocket = null;
static PrintStream os = null;
static BufferedReader is = null;
static BufferedReader ulazKonzola = null;
static boolean kraj = false;
static char username;
static char password;
public static void main(String[] args) {
try {
int port = 2222;
if(args.length>0)port = Integer.parseInt(args[0]);
clientSocket = new Socket("localhost",port); ulazKonzola = new BufferedReader(new
InputStreamReader(System.in));

os = new PrintStream(clientSocket.getOutputStream());
is = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
new Thread(new ChatKlient()).start();
while (!kraj) {
os.println(ulazKonzola.readLine());
}

clientSocket.close();
} catch (UnknownHostException e) {
System.err.println("Don't know about host ");
}catch (IOException e) {
System.err.println("IOException: " + e);
}
}

public void run() {
String linijaOdServera;
try {
while ((linijaOdServera = is.readLine()) != null) {
System.out.println(linijaOdServera);

if (linijaOdServera.indexOf("*** Dovidjenja") == 0) {
kraj = true;
return;
}
}
} catch (IOException e) {
System.err.println("IOException: " + e);
}
}
}

Code for ClientThread:

import java.io.*;
import java.net.*;

public class KlijentNit extends Thread {

BufferedReader is = null;
PrintStream os = null;
Socket soket = null;
KlijentNit[] klijenti;

public KlijentNit(Socket soket, KlijentNit[] klijent) {
this.soket = soket;
this.klijenti = klijent;
}
public void run() {
String linija;
String ime;
try {
is = new BufferedReader(new InputStreamReader(soket.getInputStream()));
os = new PrintStream(soket.getOutputStream());

os.println("Unesite ime.");
ime = is.readLine();

os.println("Dobrodosao/la " + ime + ".\nZa izlaz unesite /quit");
for (int i = 0; i <= 9; i++) {
if (klijenti != null && klijenti != this) {
klijenti.os.println("*** Novi korisnik: " + ime + " je usao u chat sobu !!! ***");
}
}

while (true) {
linija = is.readLine();
if (linija.startsWith("/quit")) {
break;
}
for (int i = 0; i <= 9; i++) {
if (klijenti != null) {
klijenti.os.println("<" + ime + "> " + linija);
}
}
}
for (int i = 0; i <= 9; i++) {
if (klijenti != null && klijenti != this) {
klijenti.os.println("*** Korisnik " + ime + " izlazi iz chat sobe !!! ***");
}
}
os.println("*** Dovidjenja " + ime + " ***");


soket.close();
} catch (IOException ex) {
ex.printStackTrace();
for (int i = 0; i <= 9; i++) {
if (klijenti == this) {
klijenti = null;
}
}

}
}
}

I want to make server/client chat,for a many clients,but each of them must has a Inbox(for private messages,for communication "client to client"),every client must first register(username,password) and I have a base (for example. txt file) which will keep the names of all users and their messages.
PLEASE HELP ME.
Back to top Go down
View user profile
 

Java Login System

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Developers 4 Fun ::  :: -