Android Open Source - Orlib User Password Authenticator

From Project

Back to project page Orlib.


The source code is released under:

GNU Lesser General Public License

If you think the Android project Orlib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.sourceforge.jsocks.socks.server;
/*from  w ww.j  a  v  a 2  s  .  co  m*/

  This class implements SOCKS5 User/Password authentication scheme as
  defined in rfc1929,the server side of it.
public class UserPasswordAuthenticator extends  ServerAuthenticatorNone{

   static final int METHOD_ID = 2;

   UserValidation validator;

    Construct a new UserPasswordAuthentication object, with given
    UserVlaidation scheme.

    @param validator UserValidation to use for validating users.
   public UserPasswordAuthenticator(UserValidation validator){
      this.validator = validator;

   public ServerAuthenticator startSession(Socket s) throws IOException{
     InputStream in = s.getInputStream();
     OutputStream out = s.getOutputStream();

     if( != 5) return null; //Drop non version 5 messages.

       return null;
       return null;

     return new ServerAuthenticatorNone(in,out);

//Private Methods

   private boolean doUserPasswordAuthentication(Socket s,
                                                InputStream in,
                                                OutputStream out) 
                                                throws IOException{
     int version =;
     if(version != 1) return false;
     int ulen =;
     if(ulen < 0) return false;
     byte[] user = new byte[ulen];;
     int plen =;
     if(plen < 0) return false;
     byte[] password = new byte[plen];;

     if(validator.isUserValid(new String(user), new String(password),s)){
       //System.out.println("user valid");
       out.write(new byte[]{1,0});
       //System.out.println("user invalid");
       out.write(new byte[]{1,1});
       return false;

     return true;

Java Source Code List