DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow Password field !

    Hey;

    I have tried too many things to solve it without any results :
    comparing a password field ..

    Well I know that for example in a JTextField :
    JTextField.getText() //not preferable but it returns a string and this is the good side.
    But I have tried both of those : (on runtime i fill the password field with "123")
    > jLabel1.setText(jTextField1.getText()); //print the "123"
    > if(jTextField1.getText() == "123") //FALSE !!
    Of course I have tried to put it in a string, and to be sure that the 123 are only '123' without any thing else !

    Now I used also to check the getpassword method like that :

    char[] pass = jTextField1.getPassword();

    and I have tried every thing ! .. char[0] contains 1 , char[1] -> 2 , char[2] -> 3 ... but they r never equals to their values , and when putting them in a string and makinf the if(str=="123") the result is false forever ..

    I don't know what is the mistake in this .. it printes them correctly, output them and all , but they r not equal to their equivalent values so what ?

    Thanks for answer .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  2. #2
    Join Date
    Dec 2005
    Posts
    97
    dont use == when comparing string. use the .equals(String str) method

    if(str.equals("123"))

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    == will compare the Strings memory addresses, not their values.
    Last edited by Phaelax; 01-31-2007 at 08:09 PM. Reason: typo

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Thank you anubis and Phalex , it works but if it compares memory adresses how it works with every thing else exept the strings objects ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #5
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    ah u meant "String" I see , so the string only can't compare this .

    Thanks .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

Similar Threads

  1. Replies: 0
    Last Post: 06-08-2006, 02:30 PM
  2. Using Passwords for Log-in's
    By Tricia in forum VB Classic
    Replies: 6
    Last Post: 03-30-2002, 01:23 PM
  3. Re: Password field read by javascript
    By Edison in forum Java
    Replies: 0
    Last Post: 03-12-2001, 10:30 PM
  4. Ted, you're a prince!
    By Georgiana Trigg in forum VB Classic
    Replies: 0
    Last Post: 10-29-2000, 11:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links