Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Buddhika85 2 posts 82 karma points
    Aug 07, 2018 @ 15:16
    Buddhika85
    0

    Validate Umbraco Back Office Users programmatically

    Hi, Im new to umbraco and currently faced with below issue.

    I have a requirement to validate for the existence of umbraco backoffice users (users in umbracoUser table) inside a SurfaceController by using a user entered username and a password, and this is what I have done so far.

    var result = new Umbraco.Web.Security.Providers.UsersMembershipProvider().ValidateUser(username, password);
    

    When I used the above statement to validate with existing username and a correct password, it always returns false and it locks the user by setting a DateTime value to lastLockoutDate column in umbracoUser table. And it sets userNoConsole = 1 in umbracoUser table as well.

    Looked into below post as well, but it did not help.

    https://our.umbraco.com/forum/umbraco-cloud/76499-umbraco-7-user-login-backoffice-programmatically

    Any guidance on how to validate the existence of back office users programmatically would be a big help.

    Appreciate your help.

    Thanks.

  • Louis Ferreira 69 posts 265 karma points
    Aug 08, 2018 @ 10:19
    Louis Ferreira
    100

    Hi Buddhika,

    Can you explain what you mean by 'validate for existence'? Are you wanting to find out if a user has login to backoffice, or you want to find out if the users credentials are valid?

    To find out if the user has backoffice access, you can use the UserService to check that they exist:

    var userExists = UmbracoContext.Current.Application.Services.UserService.Exists("theirUsername");
    

    If you want to validate their credentials, you can use

    var valid = UmbracoContext.Current.Security.ValidateBackOfficeCredentials("username", "password");
    

    Disclaimer! Please keep backoffice users credentials safe!

    Hope this helps

    Louis

  • Buddhika85 2 posts 82 karma points
    Aug 09, 2018 @ 10:42
    Buddhika85
    0

    Hi Louis,

    Thanks a lot for the reply. And applogies, for not being clear. Yes, I wanted to check whether the credentials are valid or not. And yes, your answer worked for me and now Im progressing with the rest of the implementation.

    Below is the working statement.

    var valid = UmbracoContext.Security.ValidateBackOfficeCredentials(backOfficeUser.Username, backOfficeUser.Password);
    

    Finally, yes I agree, I should keep/pass/use the back office user credentials in a safer way.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft