Page 1 of 1

Make a custom login

Posted: 04 Oct 2014, 18:14
by isador34
Hi, sorry in advance if this topic are already created,

I would like make a custom login, but I don't know how to process, can you help me?

Re: Make a custom login

Posted: 04 Oct 2014, 20:07
by Lapo
Hi,
you can follow this tutorial:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3

If you are not familiar with how SmartFox Extensions work take a look at this video first:
https://www.youtube.com/watch?v=nKGxhwJ ... 94B9D7C3E5

Also if you plan to use a database I highly recommend to use the LoginAssistant Component which provides an easier way to handle user login.
http://docs2x.smartfoxserver.com/Develo ... -assistant

cheers

Re: Make a custom login

Posted: 04 Oct 2014, 21:50
by isador34
my code don't work:

server:

Code: Select all

public class Login extends BaseServerEventHandler {

	private boolean allowUser = false;
	
	@Override
	public void handleServerEvent(ISFSEvent event) throws SFSException {
		trace("auth");
		
		String username = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
		String password = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
		
		if(!allowUser)
		{
			SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
			data.addParameter(username);
			throw new SFSLoginException("Login failed for user: "  + username, data);
		}
		
		if(username.equals("isador") && password.equals("1234"))
		{
			allowUser = true;
		}
	     
		/*if(userName.equals("isador") && cryptedPass.equals("1234"))
		{
			trace("good user");
			int response = 1;
			ISFSObject connexionOut = new SFSObject();
			connexionOut.putInt("connectServerResponse", response);
			send("Connexion", connexionOut, user);
			trace("response: "+response);
			trace("autorisation");
		}
		else
		{
			int response = 0;
			ISFSObject connexionOut = new SFSObject();
			connexionOut.putInt("connectServerResponse", response);
			send("Connexion", connexionOut, user);
			trace("response: "+response);
			trace("non autoriser");
		}*/
		
	} 

}
Client:

Code: Select all

sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
void OnLogin(BaseEvent e)
	{
		if ( (bool)e.Params["success"] ) {
			print ("Login for user \"" + (string)e.Params["name"] +  "\" successful.");
			Application.LoadLevel("MainMenu2");
			// Lets wait for the room list
		} else {
			// Login failed - lets display the error message sent to us
			print ("Login error: " + (string)e.Params["error"]);
		}
	}

	public void OnLoginError(BaseEvent e)
	{
		Debug.Log("Login error ("+e.Params["errorCode"]+"): "+e.Params["errorMessage"]);
	}

	public void OnConnection(BaseEvent e)
	{
		if((bool)e.Params["success"])
		{
			Debug.Log("Succesfully Connected");
			if(connect == true)
			{
				sfs.Send(new LoginRequest(gmm.username, gmm.password, ZoneName));
			}
		}
		else
		{
			Debug.Log("Connection Failled");
		}
	}

but when I take isador for username and 1234 for password, unity don't want load scene number 2, and I don't have print in OnLogin func

Re: Make a custom login

Posted: 06 Oct 2014, 20:17
by Lapo
The password sent by the client is encrypted for security, but you seem to compare it directly with a string in clear. This will not work.
To properly verify the password you need to call:

Code: Select all

getApi().checkSecurePassword(session, clearPass, encryptedPass);
As explained here:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3

See the "Secure Password" section

Thanks

Re: Make a custom login

Posted: 10 Oct 2014, 14:40
by isador34
I think that I use LoginAssistantComponent for my login system, I just need a BDD

Re: Make a custom login

Posted: 14 Dec 2019, 11:20
by HTCraft
When I enable custom password check (line 66 in code)

Code: Select all

lac.getConfig().customPasswordCheck = true;
in the LoginAssistantComponent SFS falls with error
----------------------------------------------------------------------------------------------------------------------------------
Exception in thread "main" java.lang.NoSuchFieldError: customPasswordCheck
at com.dsm.controller.LoginController.init(LoginController.java:66)
at com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExt
ension(SFSExtensionManager.java:303)
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFS
ZoneManager.java:426)
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZone
s(SFSZoneManager.java:239)
at com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:297)
at com.smartfoxserver.v2.Main.main(Main.java:14)
----------------------------------------------------------------------------------------------------------------------------------
Pre & Post process handlers are defined.
What is wrong?

Re: Make a custom login

Posted: 15 Dec 2019, 09:00
by Lapo
The error seem to indicate that you have a compilation issue. Make sure to recompile your code without errors and re-deploy your Extension.

Thanks

Re: Make a custom login

Posted: 15 Dec 2019, 13:11
by HTCraft
Lapo wrote:The error seem to indicate that you have a compilation issue. Make sure to recompile your code without errors and re-deploy your Extension.
I have done it several times and always get this error :(
No errors with compilation.

Re: Make a custom login

Posted: 16 Dec 2019, 06:55
by HTCraft
This parameter (customPasswordCheck) is absent in the code of LoginAssistantComponent!

Code: Select all

public class LoginAssistantComponent
{
...
    private final LoginConfiguration config;
...   
    public LoginConfiguration getConfig() {
        return this.config;
    }
}

Code: Select all

package com.smartfoxserver.v2.components.login;

import com.smartfoxserver.v2.db.IDBManager;
import java.util.List;

public final class LoginConfiguration
{
    public String loginTable;
    public String userNameField;
    public String passwordField;
    public boolean useCaseSensitiveNameChecks;
    public String nickNameField;
    public List<String> extraFields;
    public ILoginAssistantPlugin preProcessPlugin;
    public ILoginAssistantPlugin postProcessPlugin;
    public IDBManager customDBManager;
    
    public LoginConfiguration() {
        this.loginTable = "users";
        this.userNameField = "username";
        this.passwordField = "password";
        this.useCaseSensitiveNameChecks = false;
        this.nickNameField = null;
        this.extraFields = null;
        this.preProcessPlugin = null;
        this.postProcessPlugin = null;
        this.customDBManager = null;
    }
}
Check please the LoginAssistant.jar!

Re: Make a custom login

Posted: 16 Dec 2019, 10:10
by Lapo
HTCraft wrote:
Lapo wrote:The error seem to indicate that you have a compilation issue. Make sure to recompile your code without errors and re-deploy your Extension.
I have done it several times and always get this error :(
No errors with compilation.
The NoSuchField error definitely indicates a compilation issue. See here fore more details:
https://stackoverflow.com/questions/668 ... error-java

Maybe what is happening is that you're compiling with old SFS2X libraries and deploying to a more recent version of SmartFoxServer 2X.
Make sure that the libraries used for compilation come from the same release of SFS2X.
Check please the LoginAssistant.jar!
There is no such file in our SFS2X distributions. What you're referring to?

Thanks

Re: Make a custom login

Posted: 16 Dec 2019, 11:35
by HTCraft
I downloaded this module from http://docs2x.smartfoxserver.com/Extens ... -assistant
Today I installed the 2.14 version of SFS.

Re: Make a custom login

Posted: 16 Dec 2019, 15:07
by Lapo
HTCraft wrote:I downloaded this module from http://docs2x.smartfoxserver.com/Extens ... -assistant
Today I installed the 2.14 version of SFS.
You don't need to download it. SFS 2X 2.14 already has a more updated version.

It's also said right before the download link:
"If you are using SmartFoxServer 2X v2.7.0 or later, skip this step as the component is already available."

Please remove the jar file, as it's likely the cause of the problem.
Cheers

Re: Make a custom login

Posted: 16 Dec 2019, 17:03
by HTCraft
Lapo wrote: If you are using SmartFoxServer 2X v2.7.0 or later, skip this step as the component is already available.

Please remove the jar file, as it's likely the cause of the problem.
Cheers
Thanks!
:roll:

Re: Make a custom login

Posted: 16 Dec 2019, 17:13
by HTCraft
Remove LoginAssistant.jar in lib folder, restart SFS and don't get an error anymore!
Problem is solved!