I have this class to check my login stuff:
Code: Select all
package sfsext;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.exceptions.SFSErrorCode;
import com.smartfoxserver.v2.exceptions.SFSErrorData;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.exceptions.SFSLoginException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import java.sql.SQLException;
public class LoginEventHandler extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException {
try {
trace("New player login!");
String name = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
String pass = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
trace("NAME: " + name + " PASS: "+pass);
IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
String sql = "SELECT userPass,userId FROM users WHERE userName='" + name + "'";
ISFSArray res = dbManager.executeQuery(sql);
if (!getApi().checkSecurePassword(session, res.getUtfString(20), pass)) {
SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
data.addParameter(name);
throw new SFSLoginException("Login failed for user: " + name, data);
}
trace("Value of the array: " + res.getDump());
} catch (SQLException ex) {
trace(ex);
}
}
}
Database is ok, but I get a hash from the client. I figured it out that the server send the pass in a hash form becouse of some security stuff.
I tired to compare the pass in the database with the pass i get, but firstly I can't get the session variable. Compiler says smthing like no such a variable in my class. Secondly I can't figure out what integer should I use in the res.getUtfString(20) method. (I just randomly wroted 20)
I hope you can help me out.
~ Laxi