Make a custom login

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

isador34
Posts: 8
Joined: 20 Sep 2014, 12:23

Make a custom login

Postby isador34 » 04 Oct 2014, 18:14

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?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Make a custom login

Postby Lapo » 04 Oct 2014, 20:07

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
Lapo
--
gotoAndPlay()
...addicted to flash games
isador34
Posts: 8
Joined: 20 Sep 2014, 12:23

Re: Make a custom login

Postby isador34 » 04 Oct 2014, 21:50

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
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Make a custom login

Postby Lapo » 06 Oct 2014, 20:17

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
Lapo

--

gotoAndPlay()

...addicted to flash games
isador34
Posts: 8
Joined: 20 Sep 2014, 12:23

Re: Make a custom login

Postby isador34 » 10 Oct 2014, 14:40

I think that I use LoginAssistantComponent for my login system, I just need a BDD
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 14 Dec 2019, 11:20

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?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Make a custom login

Postby Lapo » 15 Dec 2019, 09:00

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
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 15 Dec 2019, 13:11

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.
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 16 Dec 2019, 06:55

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!
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Make a custom login

Postby Lapo » 16 Dec 2019, 10:10

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
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 16 Dec 2019, 11:35

I downloaded this module from http://docs2x.smartfoxserver.com/Extens ... -assistant
Today I installed the 2.14 version of SFS.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Make a custom login

Postby Lapo » 16 Dec 2019, 15:07

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
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 16 Dec 2019, 17:03

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:
User avatar
HTCraft
Posts: 27
Joined: 28 Jun 2018, 09:51
Location: Moscow, Russia
Contact:

Re: Make a custom login

Postby HTCraft » 16 Dec 2019, 17:13

Remove LoginAssistant.jar in lib folder, restart SFS and don't get an error anymore!
Problem is solved!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 156 guests