Thread: class interface or enum expected error

Results 1 to 7 of 7
  1. #1 class interface or enum expected error 
    Ikram
    Guest
    Here's the source:
    Code:
    /**
     * vBulletin class
     * @author Mad Turnip
     */
    
    import java.sql.*;
    
    public class vBulletin implements Runnable {
    	
    	
    	private Connection connection = null;
    	private Statement statement = null;
    	private static Thread thread = null;
    	
    	public enum Type {
    		myBB,
    		SMF,
    		IPB,
    		vBulletin,
    		phpBB,
    	}
    
    	private String[] tableNames = new String[6];
    	private void setTables(){
    		if(forum == Type.myBB){
    			tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
    		} else if(forum == Type.SMF){
    			tableNames = new String[] {"smf_","username","password","password","usergroupid",};
    		} else if(forum == Type.IPB){
    			tableNames = new String[] {"members","name","converge_pass_hash","converge_pass_salt","mgroup",};
    		} else if(forum == Type.vBulletin){//vbulletin
    			tableNames = new String[] {"user","username","password","salt","usergroupid",};
    		} else if(forum == Type.phpBB){//phpBB
    			tableNames = new String[] {"users","username","user_password","user_password","group_id",};
    		}
    	}
    	
    	public vBulletin(String url,String database,String username,String password,Type t){
    		this.hostAddress = "jdbc:mysql://"+url+"/"+database;
    		this.username = username;
    		this.password = password;
    		this.forum = t;
    		try {
    			//connect();
    			thread = new Thread(this);
    			thread.start();
    		} catch(Exception e){
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	
    	private final String hostAddress;
    	private final String username;
    	private final String password;
    	private final Type forum;
    	
    	private void connect(){
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch(Exception e2){
    			System.out.println("Cannot find mySql Driver.");
    			return;
    		}
    		try {
    			connection = DriverManager.getConnection(hostAddress, username,password);
    			statement = connection.createStatement();
    		} catch(Exception e){
    			System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	private void ping(){
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
    			results = statement.executeQuery(query);
    		} catch(Exception e){
    			connection = null;
    			connect();
    			e.printStackTrace();
    		}
    	}
    	
    	public void run(){
    		boolean allowRun = true;
    		while(allowRun){
    			try {
    				if(connection == null) {
    					setTables();
    					connect();
    				} else {
    					ping();
    				}
    				thread.sleep(10000);
    			} catch(Exception e){
    			}
    		}
    	}
    	/**
    	 * returns 2 integers, the return code and the usergroup of the player
    	 */
    	
    	public int[] checkUser(String name,String password){
    		int i = 0;
    		int[] returnCodes = {0,0};//return code for client, group id
    
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
    			try {
    			if(statement == null)
    				statement = connection.createStatement();
    			} catch(Exception e5){
    				statement = null;
    				connection = null;
    				connect();
    				statement = connection.createStatement();
    			}
    			results = statement.executeQuery(query);
    			if(results.next()){
    				String salt = results.getString(tableNames[3]);
    				String pass = results.getString(tableNames[2]);
    				int group = results.getInt(tableNames[4]);
    				returnCodes[1] = group;
    				String pass2 = "";
    				if(forum == Type.myBB){
    					pass2 = MD5.MD5(salt);
    					pass2 = MD5.MD5(pass2+password);
    				} else if(forum == Type.vBulletin){
    					pass2 = MD5.MD5(password);
    					pass2 = MD5.MD5(pass2+salt);
    				} else if(forum == Type.SMF){
    					pass2 = MD5.SHA((name.toLowerCase())+password);
    				} else if(forum == Type.phpBB){
    					pass2 = MD5.MD5(password);
    				} else if(forum == Type.IPB){
    					pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
    				}
    				if(pass.equals(pass2)){
    					returnCodes[0] = 2;
    					return returnCodes;
    				} else {
    					returnCodes[0] = 3;
    					return returnCodes;
    				}
    			} else {
    				//no user exists
    				returnCodes[0] = 12;
    				return returnCodes;
    			}
    		} catch(Exception e){
    			statement = null;
    			returnCodes[0] = 8;
    			return returnCodes;
    				}
    			
    			}
    		}
    	}
    It's from the integration tutorial.

    error:


    If you can rewrite the code with the error fixed i'll pay you $2 via paypal
    Reply With Quote  
     

  2. #2  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    add one more } at the bottom
    Reply With Quote  
     

  3. #3  
    Respected Member


    Josh's Avatar
    Join Date
    Aug 2008
    Age
    29
    Posts
    2,863
    Thanks given
    6
    Thanks received
    1,342
    Rep Power
    5000
    Code:
    /**
    * vBulletin class
    * @author Mad Turnip
    */
    
    import java.sql.*;
    
    public class vBulletin implements Runnable {
    	
    	
    	private Connection connection = null;
    	private Statement statement = null;
    	private static Thread thread = null;
    	
    	public enum Type {
    		myBB,
    		SMF,
    		IPB,
    		vBulletin,
    		phpBB,
    	}
    
    	private String[] tableNames = new String[6];
    	private void setTables(){
    		if(forum == Type.myBB){
    			tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
    		} else if(forum == Type.SMF){
    			tableNames = new String[] {"smf_","username","password","password","usergroupid",};
    		} else if(forum == Type.IPB){
    			tableNames = new String[] {"members","name","converge_pass_hash","converge_pass_salt","mgroup",};
    		} else if(forum == Type.vBulletin){//vbulletin
    			tableNames = new String[] {"user","username","password","salt","usergroupid",};
    		} else if(forum == Type.phpBB){//phpBB
    			tableNames = new String[] {"users","username","user_password","user_password","group_id",};
    		}
    	}
    	
    	public vBulletin(String url,String database,String username,String password,Type t){
    		this.hostAddress = "jdbc:mysql://"+url+"/"+database;
    		this.username = username;
    		this.password = password;
    		this.forum = t;
    		try {
    			//connect();
    			thread = new Thread(this);
    			thread.start();
    		} catch(Exception e){
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	
    	private final String hostAddress;
    	private final String username;
    	private final String password;
    	private final Type forum;
    	
    	private void connect(){
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch(Exception e2){
    			System.out.println("Cannot find mySql Driver.");
    			return;
    		}
    		try {
    			connection = DriverManager.getConnection(hostAddress, username,password);
    			statement = connection.createStatement();
    		} catch(Exception e){
    			System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	private void ping(){
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
    			results = statement.executeQuery(query);
    		} catch(Exception e){
    			connection = null;
    			connect();
    			e.printStackTrace();
    		}
    	}
    	
    	public void run(){
    		boolean allowRun = true;
    		while(allowRun){
    			try {
    				if(connection == null) {
    					setTables();
    					connect();
    				} else {
    					ping();
    				}
    				thread.sleep(10000);
    			} catch(Exception e){
    			}
    		}
    	}
    	/**
    	* returns 2 integers, the return code and the usergroup of the player
    	*/
    	
    	public int[] checkUser(String name,String password){
    		int i = 0;
    		int[] returnCodes = {0,0};//return code for client, group id
    
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
    			try {
    				if(statement == null)
    				statement = connection.createStatement();
    			} catch(Exception e5){
    				statement = null;
    				connection = null;
    				connect();
    				statement = connection.createStatement();
    			}
    			results = statement.executeQuery(query);
    			if(results.next()){
    				String salt = results.getString(tableNames[3]);
    				String pass = results.getString(tableNames[2]);
    				int group = results.getInt(tableNames[4]);
    				returnCodes[1] = group;
    				String pass2 = "";
    				if(forum == Type.myBB){
    					pass2 = MD5.MD5(salt);
    					pass2 = MD5.MD5(pass2+password);
    				} else if(forum == Type.vBulletin){
    					pass2 = MD5.MD5(password);
    					pass2 = MD5.MD5(pass2+salt);
    				} else if(forum == Type.SMF){
    					pass2 = MD5.SHA((name.toLowerCase())+password);
    				} else if(forum == Type.phpBB){
    					pass2 = MD5.MD5(password);
    				} else if(forum == Type.IPB){
    					pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
    				}
    				if(pass.equals(pass2)){
    					returnCodes[0] = 2;
    					return returnCodes;
    				} else {
    					returnCodes[0] = 3;
    					return returnCodes;
    				}
    			} else {
    				//no user exists
    				returnCodes[0] = 12;
    				return returnCodes;
    			}
    		} catch(Exception e){
    			statement = null;
    			returnCodes[0] = 8;
    			return returnCodes;
    		}
    		
    	}
    }
    Quote Originally Posted by Michael View Post
    add one more } at the bottom
    Actually there was one more than necessary
    Reply With Quote  
     

  4. #4  
    Ikram
    Guest
    Quote Originally Posted by Josh View Post
    Code:
    /**
    * vBulletin class
    * @author Mad Turnip
    */
    
    import java.sql.*;
    
    public class vBulletin implements Runnable {
    	
    	
    	private Connection connection = null;
    	private Statement statement = null;
    	private static Thread thread = null;
    	
    	public enum Type {
    		myBB,
    		SMF,
    		IPB,
    		vBulletin,
    		phpBB,
    	}
    
    	private String[] tableNames = new String[6];
    	private void setTables(){
    		if(forum == Type.myBB){
    			tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
    		} else if(forum == Type.SMF){
    			tableNames = new String[] {"smf_","username","password","password","usergroupid",};
    		} else if(forum == Type.IPB){
    			tableNames = new String[] {"members","name","converge_pass_hash","converge_pass_salt","mgroup",};
    		} else if(forum == Type.vBulletin){//vbulletin
    			tableNames = new String[] {"user","username","password","salt","usergroupid",};
    		} else if(forum == Type.phpBB){//phpBB
    			tableNames = new String[] {"users","username","user_password","user_password","group_id",};
    		}
    	}
    	
    	public vBulletin(String url,String database,String username,String password,Type t){
    		this.hostAddress = "jdbc:mysql://"+url+"/"+database;
    		this.username = username;
    		this.password = password;
    		this.forum = t;
    		try {
    			//connect();
    			thread = new Thread(this);
    			thread.start();
    		} catch(Exception e){
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	
    	private final String hostAddress;
    	private final String username;
    	private final String password;
    	private final Type forum;
    	
    	private void connect(){
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch(Exception e2){
    			System.out.println("Cannot find mySql Driver.");
    			return;
    		}
    		try {
    			connection = DriverManager.getConnection(hostAddress, username,password);
    			statement = connection.createStatement();
    		} catch(Exception e){
    			System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	private void ping(){
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
    			results = statement.executeQuery(query);
    		} catch(Exception e){
    			connection = null;
    			connect();
    			e.printStackTrace();
    		}
    	}
    	
    	public void run(){
    		boolean allowRun = true;
    		while(allowRun){
    			try {
    				if(connection == null) {
    					setTables();
    					connect();
    				} else {
    					ping();
    				}
    				thread.sleep(10000);
    			} catch(Exception e){
    			}
    		}
    	}
    	/**
    	* returns 2 integers, the return code and the usergroup of the player
    	*/
    	
    	public int[] checkUser(String name,String password){
    		int i = 0;
    		int[] returnCodes = {0,0};//return code for client, group id
    
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
    			try {
    				if(statement == null)
    				statement = connection.createStatement();
    			} catch(Exception e5){
    				statement = null;
    				connection = null;
    				connect();
    				statement = connection.createStatement();
    			}
    			results = statement.executeQuery(query);
    			if(results.next()){
    				String salt = results.getString(tableNames[3]);
    				String pass = results.getString(tableNames[2]);
    				int group = results.getInt(tableNames[4]);
    				returnCodes[1] = group;
    				String pass2 = "";
    				if(forum == Type.myBB){
    					pass2 = MD5.MD5(salt);
    					pass2 = MD5.MD5(pass2+password);
    				} else if(forum == Type.vBulletin){
    					pass2 = MD5.MD5(password);
    					pass2 = MD5.MD5(pass2+salt);
    				} else if(forum == Type.SMF){
    					pass2 = MD5.SHA((name.toLowerCase())+password);
    				} else if(forum == Type.phpBB){
    					pass2 = MD5.MD5(password);
    				} else if(forum == Type.IPB){
    					pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
    				}
    				if(pass.equals(pass2)){
    					returnCodes[0] = 2;
    					return returnCodes;
    				} else {
    					returnCodes[0] = 3;
    					return returnCodes;
    				}
    			} else {
    				//no user exists
    				returnCodes[0] = 12;
    				return returnCodes;
    			}
    		} catch(Exception e){
    			statement = null;
    			returnCodes[0] = 8;
    			return returnCodes;
    		}
    		
    	}
    }


    Actually there was one more than necessary
    Ok, that error is gone but had brought upon new ones.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Jul 2008
    Posts
    1,043
    Thanks given
    209
    Thanks received
    46
    Rep Power
    0
    What errors did you get?
    Reply With Quote  
     

  6. #6  
    Ikram
    Guest
    Quote Originally Posted by Artificial Intelligence View Post
    What errors did you get?
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Jan 2008
    Posts
    2,340
    Thanks given
    20
    Thanks received
    575
    Rep Power
    1202
    Code:
    public int load;
    You're also missing the constructor for the MD5 class.
    Just replace yours with this. The important part has been bolded.
    MD5 class:

    Code:
    import java.security.*;
    
    public class MD5 {
        private String inStr;
        private MessageDigest md5;
    
        public MD5(String inStr) {
    	this.inStr = inStr;
           	try {
    	    this.md5 = MessageDigest.getInstance("MD5");
            } catch (Exception e) {
    	    System.out.println(e.toString());
    	    e.printStackTrace();
            }
        }
    
        public String compute() {
            try {
    	    char[] charArray = this.inStr.toCharArray();
    	    byte[] byteArray = new byte[charArray.length];
    	    for (int i=0; i<charArray.length; i++)
    	        byteArray[i] = (byte) charArray[i];
    	    byte[] md5Bytes = this.md5.digest(byteArray);
            	StringBuffer hexValue = new StringBuffer();
    	    for (int i=0; i<md5Bytes.length; i++) {
    	        int val = ((int) md5Bytes[i] ) & 0xff; 
    	        if (val < 16) hexValue.append("0");
    	            hexValue.append(Integer.toHexString(val));
    	    }
    	    return hexValue.toString();
            } catch(Exception e) { 
                return "null"; 
            }
        }
    
        public static void main(String[] args){
            String saltM = new MD5("mj5ml").compute();
    	String passM = new MD5("daltonspassword").compute();
    	String finalPass = new MD5(saltM + passM).compute();
    	System.out.println(finalPass);
        }
    }
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •