DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Force Logout user

 6 Replies
 2 Subscribed to this topic
 30 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 2
New Around Here

In the user login process, I need a solution to sign the user out from all other browsers.

Here’s my current code:

<code>var portalSecurity = new PortalSecurity(); </code>

<code>PortalSettings portalSettings = PortalController.GetCurrentPortalSettings(); </code>

<code>var user = UserController.GetCachedUser(portalSettings.PortalId, "azarbara"); </code>

<code>portalSecurity.SignOut(); DataCache.ClearUserCache(portalSettings.PortalId, "azarbara"); </code>

This code signs the user out from the current browser only, not from all other browsers where they're logged in. Does anyone have any ideas?

 

Advanced Member
Posts: 207
Advanced Member
Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

SORRY: Same code, ignore it.

Try this..,, https://github.com/Rocket...ts/User/UserUtils.cs

public static void SignOut()
{
var ps = new PortalSecurity();
ps.SignOut();
}

I am unsure if it logs out from all browsers.  

 

 

Advanced Member
Posts: 207
Advanced Member
Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!
Maybe try to cancel authorise and the autorise again...

public static void UnAuthoriseUser(int portalId, int userId)
{
var userInfo = UserController.GetUserById(portalId, userId);
if (userInfo != null)
{
userInfo.Membership.Approved = false;
UserController.UpdateUser(portalId, userInfo);
}
}
public static void AuthoriseUser(int portalId, int userId)
{
var userInfo = UserController.GetUserById(portalId, userId);
if (userInfo != null)
{
userInfo.Membership.Approved = true;
UserController.UpdateUser(portalId, userInfo);
}
}
New Around Here
Posts: 2
New Around Here

David

this code logout user only from current browser

 

New Around Here
Posts: 2
New Around Here

It seems that this solution is not a good solution to solve my problem

because this method makes the user UnAuthoriseUser and the user cannot login in again the current browser

unless I authorize the user again after this function, which will not cause logout user from other browsers .

i think in the side of the cookies stored in the browser or the last IP stored in the database for the user's login should do something
 

Advanced Member
Posts: 207
Advanced Member
Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

Yes, that makes sense!
I don;t think changing the [AuthCookies] table will solve the problem, besides you'll probably have to restart to get the change.
You could try making the last activity last year.

// update LastActivityDate 
user.Membership.LastActivityDate = DateTime.Now.AddYear(-1);
UserController.UpdateUser(portalSettings.PortalId, user, false, false);

Senior Member
Posts: 1607
Senior Member
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

In this case, there isn't a straightforward way to do this, but I think you can make this happen by taking advantage of some of the other existing features.  

By default, DNN will have the option enabled to "Force Logout After Password Change."  This is found in the persona bar > Settings > Member Accounts view.  

If this is enabled, you could potentially flag this to occur by forcing the end-user to change their password on next login. You'd do this by editing their account in the UI, or by changing the <code>0</code> to <code>1</code> for the user account record in the <code>UpdatePassword</code> column of the <code>Users</code> table, then clearing the cache on the site.  

If these two things are done, what should happen is that the end-user is prompted on one browser to change their password on their next visit.  Then, other browsers should have an invalid cookie.  (This needs to be tested, though.)

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved