Authenticate users from custom SQL database

Posted by Community Admin on 03-Aug-2018 11:15

Authenticate users from custom SQL database

All Replies

Posted by Community Admin on 09-Aug-2011 00:00

Hi Everyone,

I have a few custom controls in SiteFinity 4 that i want to protect. These controls communicatie with their own SQL database and this database also has a users table. I've setup a small control with username and password field, and i want to redirect users to a page that has this login control. In my login control i use the standard way of creating a FormsAuthenticationTicket to login the user. 
This last bit doesn't work! It did, before, in SiteFinity 3.7, but my user never gets the IsAuthenticated status.
Can anyone point me in right direction on how to solve this / setup this login mechanism?

Thanks in advance, Tevez

Posted by Community Admin on 09-Aug-2011 00:00

Hello Tevez,

You need to use SecurityManager.AuthenticateUser

sample

User sfUser;
var result = SecurityManager.AuthenticateUser(this.MembershipProvider, this.UserName, this.Password, this.RememberMeSet, outsfUser);
boolauthenticated = result == UserLoggingReason.Success;


All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Aug-2011 00:00

This works for authenticating users that are registered within sitefinity, 
but can i use this to authenticate my customers (that are stored in a database outside sitefinity) as well?

Posted by Community Admin on 09-Aug-2011 00:00

Hello Tevez,

If you use ASP.NET Membership provider then you can use the same code. In this case it does not matter if you use separate database to store the user or the database generated by Sitefinity.

You can gather more information about how authentication works from this post.

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2011 00:00

Hi Ivan,

I see lot of information on the forum, but also lot's of questions, .. i didn't solve mine by reading all the posts. 
It looks like there is 3.7 and 4.x information (because people are upgrading). 

At some point it seems very easy to me; just write a custom membership provider, right? 
One that inherits from either Telerik.Sitefinity.Security.Data.MembershipDataProvider or Telerik.Sitefinity.Security.Data.OpenAccessMembershipProvider. 

But i tried to do so, with a class that inherits the OA provider, with some overrides for the ValidateUser methods. I registered the provider in the backend and tried to validate a user with the following code: 

UserLoggingReason reason = SecurityManager.AuthenticateUser("myMembershipProvider", txtLogin.Text.Trim(), txtPass.Text.Trim(), true);
But, nothing happens. No error. reason only has the value " Unknown" .. 

Can you perhaps post a small 1-2-3 steps guide on how to do this? I looks like you can make lot's of people happy with that! 

Thanks in advance!
Tevez 

Posted by Community Admin on 11-Aug-2011 00:00

Hello Tevez,

Could you check what returns the highlighted line?

User sfUser;

var result = SecurityManager.AuthenticateUser(this.MembershipProvider, this.UserName, this.Password, this.RememberMeSet, outsfUser);

bool authenticated = result == UserLoggingReason.Success;

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2011 00:00

Hi Ivan,

This returns false. And result = Unknown.

Does this give you any clue?

Regards, Tevez

Posted by Community Admin on 12-Aug-2011 00:00

Hello Tevez,

"Unknown" generally means Invalid username or password specified.

Success 0 User was successfully registered as logged in
UserLimitReached 1 The limit of maximum simultaneous logged in users is reached
UserNotFound 2 User not found in any provider
UserLoggedFromDifferentIp 3 User is already logged in from different IP address
SessionExpired 4 Indicates that the user logical session has expired
UserLoggedOff 5 User have the authentication cookie but does not have logged in the database or user is already logged out.
UserLoggedFromDifferentComputer 6 More than one users trying to login from the same IP but from different computers.
Unknown 7 Invalid username or password specified.
NeedAdminRights 8 User is not administrator to logout other users
UserAlreadyLoggedIn 9 User already is logged in. We need to ask the user to logout someone or himself
UserRevoked 10 User was revoked. The reason is that the user was deleted or user rights and role membership was changed.


www.sitefinity.com/.../t_telerik_sitefinity_security_userloggingreason.html

Best wishes,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed