关于密码验证,客户端输入的密码总通不过服务器验证。下面是服务器端和客户端的密码验证相关的方法服务器端
private void authenticate(){ //验证密码
try{
String passwd = in.readUTF();//private DataInputStream in = null;
if(passwd.equals(Homework_Server.PASSWD))//这里,问题不明
send("okey");
else{
send("error");
hangup();//未通过验证,断开连接
}
}
catch(IOException ioe){
hangup();
}
}
客户端,做一个applet,TextField输入密码
private void connect(){ //连接到服务器,并验证密码
try{
connection = new Socket(host,6889);//主机名,端口号
//private Socket connection = null;
out = new DataOutputStream(connection.getOutputStream());
//private DataOutputStream out = null;
in = new ObjectInputStream(connection.getInputStream());
//private ObjectInputStream in = null;
send("pass",passwd.getText());
//private TextField passwd = new TextField(10);
if(in.readUTF().equals("okay")){
status.setText("Authenticating ... connected");
connected = true;
showDirectory("pwd","dummy");
}
else
status.setText("Authenticating ... REFUSED");
}
catch(Exception e){
status.setText("Error: "+e);
}
}