Security.authenticate() always returns null in developer

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Security.authenticate() always returns null in developer

Postby dev-ws-011 » Tue Apr 16, 2019 9:28 am

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:
Code: Select all
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. :(

Any assistance in resolving above will be highly appreciated.

Thanks
Servoy Developer
dev-ws-011
 
Posts: 18
Joined: Fri Oct 21, 2016 8:23 am

Re: Security.authenticate() always returns null in developer

Postby sanneke » Tue Apr 16, 2019 11:07 am

I see you are using the string "username" and "password". I guess you wanted to use the dataproviders?
Code: Select all
var loginResult = security.authenticate([username,password]);

Regards Sanneke
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 381
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re: Security.authenticate() always returns null in developer

Postby dev-ws-011 » Tue Apr 16, 2019 11:19 am

sanneke wrote:I see you are using the string "username" and "password". I guess you wanted to use the dataproviders?
Code: Select all
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
Servoy Developer
dev-ws-011
 
Posts: 18
Joined: Fri Oct 21, 2016 8:23 am

Re: Security.authenticate() always returns null in developer

Postby sanneke » Tue Apr 16, 2019 11:25 am

You could check the user and password:
Code: Select all
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();
   }
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 381
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re: Security.authenticate() always returns null in developer

Postby sanneke » Tue Apr 16, 2019 11:30 am

I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:

security.jpg
security.jpg (119.55 KiB) Viewed 300 times
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 381
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re: Security.authenticate() always returns null in developer

Postby dev-ws-011 » Tue Apr 16, 2019 11:43 am

sanneke wrote:I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:

security.jpg


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?
Servoy Developer
dev-ws-011
 
Posts: 18
Joined: Fri Oct 21, 2016 8:23 am

Re: Security.authenticate() always returns null in developer

Postby sanneke » Tue Apr 16, 2019 11:55 am

Yes I am:

code_snippet.jpg
code_snippet.jpg (196.37 KiB) Viewed 294 times


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?

password.jpg
password.jpg (153.69 KiB) Viewed 294 times
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 381
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re: Security.authenticate() always returns null in developer

Postby dev-ws-011 » Tue Apr 16, 2019 1:05 pm

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():
1. Used Smart Client, Servoy v8.4 & v6.1.6, false is returned (username & password are valid).
2. 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.
Servoy Developer
dev-ws-011
 
Posts: 18
Joined: Fri Oct 21, 2016 8:23 am

Re: Security.authenticate() always returns null in developer

Postby sanneke » Tue Apr 16, 2019 1:19 pm

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.
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 381
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re: Security.authenticate() always returns null in developer

Postby dev-ws-011 » Tue Apr 16, 2019 2:23 pm

Thanks Sanneke.

You assistance is highly appreciated in resolving the issue. I will explore teh documnet link whcih you have shared.

Thanks once again.
Servoy Developer
dev-ws-011
 
Posts: 18
Joined: Fri Oct 21, 2016 8:23 am


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 0 guests