Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Password Checking
Ashish K. Singh
Greenhorn
Posts: 5
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.io.Console; class ConsoleTest { public static void main(String[] args) { Console conc = System.console(); String username = conc.readLine("Username :"); char[] passwd = conc.readPassword("Password :"); String corPass = "supersoul"; if(corPass.equals(passwd)) { System.out.println("Here is the info : "); System.out.println("userid : "+username); System.out.println("password : "+corPass); } else { System.out.println("Wrong password"); } } }
How can i compare
passwd
?
thanks
Ulf Dittmer
Rancher
Posts: 43081
77
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can create a
String
from a char[] using "new String(char[])". Then the "equals" method does the right thing.
Rob Spoor
Sheriff
Posts: 22781
131
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Check out java.util.Arrays
It doesn't really matter which one you use though:
char[] corPassArray = corPass.toCharArray(); Arrays.equals(corPassArray, passwd); // vs corPass.equals(new String(passwd));
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Servlet Sessions Coding
please correct the code
Console class
[newbie] Null pointer exception ??
The value for the useBean class attribute "..." is invalid.
More...