Results 1 to 9 of 9
- 06-06-2012, 09:41 PM #1
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 1
Special characters? Too same strings doesnt match...
Ok so I've go another problem. I've got a java socket multithread server and a flash client
When client clicks on login button, it sends this string <<user123 pass123>> server receives it and sort it to strings username = user123 and userpass = pass123
After that it checks if "user123" ini file exist in the src folder (username + ".ini") it finds it and reading it. user123.ini contains "password pass123"
and checks if userpass == user123's password
But the problem is that when I type the right password , it doesn't match it I don't know why...
Here is the code:
Java Code:try { INPUT = new Scanner(SOCK.getInputStream()); OUT = new PrintWriter(SOCK.getOutputStream()); Scanner checkUser = null; boolean gotusername = false; boolean gotpassword = false; boolean goteverything = false; boolean allowmenu = false; boolean gotinmenu = false; String username = "NotFound"; String userpassword = "NotFound"; while(true) { CheckConnection(); if(!INPUT.hasNext()) { return;} if(goteverything == false) { username = INPUT.next(); userpassword = INPUT.next(); System.out.println("User's username: " + username +"\n" + "User's password: " + userpassword); goteverything = true; } File userFile=new File(username+".ini"); //File userFile=new File("lionlev.ini"); System.out.println("looking for " + userFile); boolean exists = userFile.exists(); if(!exists){ System.out.println("Invalid username."); } else { try { checkUser = new Scanner(new File(username+".ini")); //checkUser = new Scanner(new File("lionlev.ini")); } catch (Exception e) {} checkUser.next(); String cpass = checkUser.next(); System.out.println("Entered pass: " + userpassword); System.out.println("REal pass: " + cpass); if(allowmenu == false){ if(userpassword == cpass){ System.out.println("Login is alright, sending "+username+ " to the menu.."); OUT.println("ok1" + EOF); OUT.flush(); allowmenu = true; } else{ System.out.println("Wrong password"); } } else { System.out.println("allowmenu is true"); } } String menu1 = INPUT.next(); while (gotinmenu == false){ if(menu1.indexOf("menu") > -1){ System.out.println("User "+username+ " is in the menu."); gotinmenu = true; } }
PLease help?Last edited by Lionlev; 06-06-2012 at 09:46 PM.
- 06-06-2012, 09:42 PM #2
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 1
Re: Special characters? Too same strings doesnt match...
Maybe I am guessing that there are some extra hidden characters? I don't know...
-
Re: Special characters? Too same strings doesnt match...
First try calling trim() on the received String to remove leading and trailing white space. If that doesn't help, loop through each character of the received String to see for yourself exactly what you're receiving. Having said all of that, all the usual warnings about not using Strings for passwords, and for holding password Strings on disk apply.
- 06-06-2012, 09:58 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,420
- Blog Entries
- 7
- Rep Power
- 17
- 06-06-2012, 10:03 PM #5
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 1
- 06-07-2012, 09:31 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Special characters? Too same strings doesnt match...
should beJava Code:if(goteverything == false)
as you did with the later 'if' statement.Java Code:if(!goteverything)
Please do not ask for code as refusal often offends.
- 06-07-2012, 11:11 AM #7
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 1
- 06-07-2012, 11:42 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,420
- Blog Entries
- 7
- Rep Power
- 17
Re: Special characters? Too same strings doesnt match...
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-07-2012, 12:20 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Escaping Special Characters
By djgovins in forum LuceneReplies: 6Last Post: 07-08-2011, 06:05 PM -
Special Characters on GUI
By keo in forum AWT / SwingReplies: 4Last Post: 05-01-2011, 10:40 PM -
Special characters question
By alexalex1234 in forum Advanced JavaReplies: 1Last Post: 03-24-2011, 11:33 AM -
XML with special characters
By Kaizah in forum XMLReplies: 1Last Post: 11-06-2009, 02:26 PM -
special characters
By ravian in forum New To JavaReplies: 2Last Post: 11-16-2007, 01:28 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks