Make a custom login
Make a custom login
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?
I would like make a custom login, but I don't know how to process, can you help me?
Re: Make a custom login
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
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
my code don't work:
server:
Client:
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
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
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:
As explained here:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3
See the "Secure Password" section
Thanks
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
I think that I use LoginAssistantComponent for my login system, I just need a BDD
Re: Make a custom login
When I enable custom password check (line 66 in code)
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?
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
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
Thanks
Re: Make a custom login
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
This parameter (customPasswordCheck) is absent in the code of LoginAssistantComponent!
Check please the LoginAssistant.jar!
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
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
I downloaded this module from http://docs2x.smartfoxserver.com/Extens ... -assistant
Today I installed the 2.14 version of SFS.
Today I installed the 2.14 version of SFS.
Re: Make a custom login
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
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!
Re: Make a custom login
Remove LoginAssistant.jar in lib folder, restart SFS and don't get an error anymore!
Problem is solved!
Problem is solved!
Who is online
Users browsing this forum: No registered users and 156 guests