Hi,
I have encountered incorrect behavior of security.authenticate() which always returns null in developer irrespective of credentials are valid or not.
Here is my code snippet:
function onSolutionOpen(arg, queryParams) {
var loginResult = security.authenticate(["username","password"]);
application.output("Login Result:"+loginResult,LOGGINGLEVEL.INFO);
if(loginResult){
var userName = security.getUserName();
application.output("User name:"+userName,LOGGINGLEVEL.INFO);
}
else
{
application.output("Login failed due to invalid credentials.",LOGGINGLEVEL.INFO);
application.exit();
}
}
Output of above code:
Login Result:
Login failed due to invalid credentials.
Note:
Code is tested for both valid and invalid credentials but same result. and also tested on Servoy 8.2 & Servoy 8.4 but same result. ![Sad :(]()
Any assistance in resolving above will be highly appreciated.
Thanks
I see you are using the string “username” and “password”. I guess you wanted to use the dataproviders?
var loginResult = security.authenticate([username,password]);
Regards Sanneke
sanneke:
I see you are using the string “username” and “password”. I guess you wanted to use the dataproviders?
var loginResult = security.authenticate([username,password]);
Regards Sanneke
Thanks Sanneke for assistance. I have tried with dataproviders as well, but it didn’t work. Also, we can pass string as I have done in code as mentioned in Servoy Documentation.
If there is any other solution please let me know.
Thanks
You could check the user and password:
var user_id = security.getUserUID(username);
var loginResult = false
if(user_id ){
loginResult = security.checkPassword(user_id, password)
}
if(loginResult){
var userName = security.getUserName();
security.login(username,user_id ,["users"])
application.output("User name:"+userName,LOGGINGLEVEL.INFO);
}
else
{
application.output("Login failed due to invalid credentials.",LOGGINGLEVEL.INFO);
application.exit();
}
I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:
[attachment=0]security.jpg[/attachment]
sanneke:
I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:
[attachment=0]security.jpg[/attachment]
Yes I have tried with valid user which is present in User and group security.
Are you able to run my code snippet successfully in developer?
Yes I am:
[attachment=1]code_snippet.jpg[/attachment]
One thing that I noticed while trying this, when you create a user, it seems his password is ‘password’ but you really have to click into the field and change it to ‘password’. Maybe that is what is missing?
[attachment=0]password.jpg[/attachment]
Yes, I have updated password field to ‘password’.
I have tried code which you have mentioned in above comments to use security.login(). Here is my summary when tried using security.login():
- Used Smart Client, Servoy v8.4 & v6.1.6, false is returned (username & password are valid).
- Used Web Client, Servoy v8.4 & v6.1.6, true is returned i.e. Successful.
Security.authenticate() is having same results as previous i.e. returning null.
Can you please mention which Servoy version you are using and which client you have used to test the code?
Thanks.
I see, we have found the problem. I was trying in 8.4 NG.
Authenticate for smart client will only work in an authentication module. In smart client the idea is that you have your solution, a login module and an authentication module. The client first will only download the login module. This login module will talk to the authentication module that runs only on the server. If the authentication module authenticates, the client can download the solution. This way he will not have the solution if he is not a valid user.
Here is more info about the process in the smart client:
https://wiki.servoy.com/display/DOCS/Im … entication
You can also use a easy solution where you just check the property ‘must authenticate’ on the solution properties and servoy will give its own login form.
Thanks Sanneke.
You assistance is highly appreciated in resolving the issue. I will explore teh documnet link whcih you have shared.
Thanks once again.