最后更新:2022-11-08 07:25:35 手机定位技术交流文章

ChangeEmailPassword.* @param username* @param oldpassword*/public ChangeEmailPassword(String username,String oldpassword) {this.username = username;this.oldpassword = oldpassword;try{conn = new Connection(HOST);conn.connect();/* Authenticate */boolean isAuthenticated = conn.authenticateWithPassword(username, oldpassword);if (isAuthenticated == false) {setErrorMessage("Authentication failed.");conn=;}}catch(Exception e){conn.close();conn = ;System.out.println(e);}}public void setNewPassword(String newpassword) {if(hasError){return;}if (conn==){return;}try{Session sess = conn.openSession();sess.execCommand("passwd");InputStream so = sess.getStdout();InputStream err = sess.getStderr();OutputStream out = sess.getStdin(); byte[] buffer = new byte[500];//其实没有必要这么大.130就差不多了.怕万一有什么提示.int length = 0;length = err.read(buffer);// if (length > 0) { // System.out.println("#1:"+ new String(buffer, 0, length)); // //(current) UNIX password: // } String coldpassword = oldpassword+"n";out.write(coldpassword.getBytes());length = err.read(buffer);// if (length > 0) { // System.out.println("#2:"+ new String(buffer, 0, length)); // //(current) UNIX password: // } String cnewpass = newpassword +"n";out.write(cnewpass.getBytes());length = err.read(buffer);if (length > 0) {String rs = new String(buffer, 0, length);//System.out.println("#3:"+rs);if(rs.indexOf("BAD")>-1){sess.close();conn.close();setErrorMessage(rs);return;}}out.write(cnewpass.getBytes());length = so.read(buffer);if (length > 0) {String rs = new String(buffer, 0, length);if(rs.indexOf("successfully")>-1){this.isSuccessfully = true;this.SystemMessage = rs;}}/* Close this session */sess.close();/* Close the connection */conn.close();} catch (IOException e) {e.printStackTrace(System.err);}}/*** @param args the command line arguments*/public static void main(String[] args) {ChangeEmailPassword cep = new ChangeEmailPassword("username", "oldpassword");if(cep.isHasError()){System.out.println(cep.getErrorMessage());cep = ;return;}cep.setNewPassword("newpassword");if(cep.isHasError()){System.out.println(cep.getErrorMessage());cep = ;return;}if(cep.isSuccessfully){System.out.println(cep.getSystemMessage());}}/*** @return the SystemMessage*/public String getSystemMessage() {return SystemMessage;}}



本文由 在线网速测试 整理编辑,转载请注明出处。