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]

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);
}
}
}
> > 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?
> 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