-
Help.. It's urgent
I'm new programmer.
I'm a new user of java programming language, I have a small problem in server and client code.
I'm creating a program that allowed user to enter their username and password, after that the program will compare the user name and the password from the data base. I'm using .txt file as my database.
On the Client side, the program will ask the user to enter his/her username and password, then it will be pass to the server. After the server receive the data, server will compare the username and password with the database.. Here, i attached my code that i've done. There are a lot of problem. I hope that you can help me. THanx in advance.
I'm using string tokenizer to get the data from the database.
My problem is, there are some error, while transfering data and receiving data.
This is my server side code:
tempUsername = in.readUTF();
System.out.println(in+":"+tempUsername);
int aaa=0;
StringTokenizer st;
BufferedReader br = new BufferedReader (new FileReader ("Pass.txt"));
boolean eof = false;
while (!eof)
{
String line = br.readLine();
if(line!=null)
{
st=new StringTokenizer(line, ":");
while(st.hasMoreTokens())
{
String x=st.nextToken();
if(tempUsername.equals(x))
{
aaa=0;
String w="Your user name is correct!";
System.out.println(w);
out.writeUTF(w);
out.flush();
String no= "1";
out.writeUTF(no);
out.flush();
String y = st.nextToken();
tempPassword = in.readUTF();
System.out.println(in+":"+tempPassword);
if(tempPassword.equals("x"))
{
String z="Your password is correct!";
out.writeUTF(z);
out.flush();
break;
}
else
{
String z="Your password is incorrect!!";
out.writeUTF(z);
out.flush();
break;
}
}
else
{
String w="Your username does not exist, please register!!";
System.out.println(w);
out.writeUTF(w);
out.flush();
}
}
}
And this is my Client side code:
System.out.println("Enter your user name: ");
String name = br.readLine();
out.writeUTF(name);
out.flush();
String valid = in.readUTF();
System.out.println(valid);
String aS="";
aS=in.readUTF();
if(aS.charAt(0)=='1')
{
System.out.println("Enter your password: ");
String pass=br.readLine();
out.writeUTF(pass);
out.flush();
String vUsername=in.readUTF();
System.out.println(vUsername);
String msg2 = in.readUTF();
System.out.println(msg2);
}
else
{
continue; //i have no idea what does continue and break are use for.
}
I hope that i can get the answer as soon as possible, i've been struggling with this coding for 2 nights, but still can't find the error.
Similar Threads
-
By sundaar in forum ASP.NET
Replies: 2
Last Post: 07-31-2006, 03:48 PM
-
By vimala in forum VB Classic
Replies: 1
Last Post: 03-22-2005, 11:18 PM
-
By Ravikant Ninave in forum VB Classic
Replies: 0
Last Post: 08-31-2001, 05:27 AM
-
By precious in forum Enterprise
Replies: 2
Last Post: 06-23-2001, 02:34 PM
-
By barnaboss in forum Java
Replies: 1
Last Post: 03-15-2001, 11:54 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks