Re: Antwort: Testing a password
Posted by
hallockk on
Apr 06, 2010; 7:49pm
URL: http://imagej.273.s1.nabble.com/Testing-a-password-tp3688636p3688644.html
Thanks!
Kevin
----- Original Message -----
Sent: Tuesday, April 06, 2010 3:32
PM
Subject: Antwort: Testing a
password
Hi Kevin,
you stumbled into one of the famous Java
gotchas!
You cannot compare a string in Java with "==", it will check
if it is
exactly **the same** object, not directly the contents!
(The compiler tries to reuse the "same" strings, so it sometimes seems
to
work somehow, as you found out!)
You need to use "equals()",
see for ex. here:
http://leepoint.net/notes-java/data/strings/12stringcomparison.html
Cheers
Mit freundlichen Grüßen / Best regards
Joachim Wesner
Projektleiter Optik Technologiesysteme
____________________________________________
Leica
Microsystems CMS GmbH | GmbH mit Sitz in Wetzlar | Amtsgericht
Wetzlar
HRB 2432
Geschäftsführer: Dr. Stefan Traeger | Dr. Wolf-Otto
Reuter | Dr. David Roy
Martyr | Colin Davis
www.leica-microsystems.com
hallockk
<[hidden email]>
Gesendet von:
An
ImageJ Interest
[hidden email]
Group
Kopie
<[hidden email].
GOV>
Thema
Testing a password
06.04.2010 21:01
Bitte antworten
an
ImageJ Interest
Group
<[hidden email].
GOV>
Hi everyone,
I'm trying to develop
some code to allow the user to type in a string
password and then test the
string. I wrote the following:
GenericDialog GetPassword = new
GenericDialog("Password");
GetPassword.addStringField(" Password: ",
"password");
GetPassword.showDialog();
String ToPass = GetPassword.getNextString();
//Message for troubleshooting
purposes
int
TestToPass = 0;
if
(ToPass == "password"){
TestToPass = 1;
}
IJ.showMessage("Password",ToPass);
String StrTestToPass =
Integer.toString(TestToPass);
IJ.showMessage("TestToPass",Integer.toString(TestToPass));
Below this troubleshooting code I have the additional actions, but
what's
become clear is that whatever string is part of the dialog isn't
being
tested properly by the IF statement. If I make a string that
equals
"password" within the code, the IF statement triggers fine, but not
when
"password" is acquired from the getNextString() function.
Thanks,
Kevin Hallock
--
View this message in
context:
http://n2.nabble.com/Testing-a-password-tp4860684p4860684.html
Sent
from the ImageJ mailing list archive at Nabble.com.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________