Password issues

I'm quoting this code from a previous post from "prometheuzz". When i tried this code no *'s appear, infact nothing appears while typing but it does tell me if it is correct or not.. nothing appears on the console while typing, can someone fix this please?

class Main{

publicstaticvoid main(String[] args){

java.io.Console console = System.console();

if(console ==null){

System.out.println("No console available.");

System.exit(1);

}

char[] secret ="Alais".toCharArray();

char[] password = console.readPassword("Enter your password: ");

if(java.util.Arrays.equals(secret, password)){

System.out.println("That is correct!");

}else{

System.out.println("Incorrect!");

}

}

}

[1500 byte] By [Ixnaya] at [2007-11-27 0:01:21]
# 1

Here, try this ... I saw this on another Thread a while back:

import java.io.*;

public class Password {

private static final DEFAULT_PWD = "xyz123";

private static byte by[] = new byte[15];

private static class PasswordMaskingThread extends Thread {

public boolean stop = false;

public void run() {

while(!stop) {

try {

this.sleep(50);

}

catch (InterruptedException ie) {

}

if (!stop) {

System.out.print("\rPlease enter your password: **********\rPlease enter your password: ");

}

System.out.flush();

}

}

}

public static void main(String[] args) throws Exception {

try {

System.out.println("Please enter yor username:");

System.in.read(by);

String name = new String(by);

System.out.println("Welcome " + name);

}

catch(IOException e) {

System.out.println("I/O error - " + e.toString());

}

System.out.println();

PasswordMaskingThread thread = new PasswordMaskingThread();

thread.start();

String pass = "";

while (true) {

char c = (char)System.in.read();

thread.stop = true;

if (c == '\n' || c == '\r') {

break;

}

else {

pass += c;

}

}

if (DEFAULT_PWD.equals(pass)) {

System.out.println("You have entered the correct password");

}

else {

System.out.println("You have entered an incorrect password");

System.exit(1);

}

}

}

abillconsla at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 2
hi,what you need is something like a passwordfield : http://java.sun.com/docs/books/tutorial/uiswing/components/passwordfield.html http://java.sun.com/javase/6/docs/api/javax/swing/JPasswordField.html
java_2006a at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 3
i got this error<identifier> expected private static final DEFAULT_PWD = "xyz123";
Ixnaya at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 4
> i got this error> <identifier> expected>private static final DEFAULT_PWD = "xyz123";Bill put a few typos in the code, just to keep you on your toes. Feel free to correct them.
DrLaszloJamfa at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 5
I saw somethings that you may be interested. http://www.java3z.com/cwbwebhome/article/article5/5716.jsp?id=1052Just ignore the Chinese characters and read the codes.
rym82a at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 6

> > i got this error

> > <identifier> expected

> >private static final DEFAULT_PWD = "xyz123";

>

> Bill put a few typos in the code, just to keep you on

> your toes. Feel free to correct them.

Yeah ... dat's da ticket! ... OP make that final String DEF ... ok?

abillconsla at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 7
getting same error<identifier> expected private static final DEF = "xyz123";
Ixnaya at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 8
private static final String DEFAULT_PWD = "xyz123";
abillconsla at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 9
> getting same error> <identifier> expected>private static final DEF = "xyz123";*sigh*
DrLaszloJamfa at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 10
awesomethanks it works now
Ixnaya at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...
# 11

> awesome

> thanks it works now

Welcome. Now, say it with

[url #" style="display: block; background-image:url('http://developers.sun.com/forums/img/silver.gif'); width: 120px; height: 120px] [/url]

Ah you did ... thank you too.

Message was edited by:

abillconsl

abillconsla at 2007-7-11 15:52:32 > top of Java-index,Java Essentials,Java Programming...