Search code examples
asp.net-mvc-3authenticationadminmembership

Login for just one member in MVC3


I am creating my own blog engine in MVC3 and I don´t want to register users to post comments and other things. I just want to have login page for admin (me) so I don´t want to implement membershipprovider. I just want to have login page and [Authorize] atribute enabled and then logout link. What is best way to do this? Thanks


Solution

  • [Authorize] attribute relies on HttpContext.Current.User IPrinicipal object to verify whether user is authenticated or not. If you don't want to implement MembershipProvider then you will have to implement some type of your own IPrinicipal object. Another solution might be to go with FormsAuthentication with a web.config setting that looks something like this:

     <authentication mode="Forms">
        <forms loginUrl="~/Account/LogOn" timeout="2880">
            <credentials passwordFormat="SHA1">
                <user name="admin" password="43206512b209ba29cb5c642edc85bdac133354fe"/> <!-- SecretPass -->
            <credentials>
        </forms>
    </authentication>
    

    Hope this help. Regards.

    EDIT: I used online SHA1 hash generator http://hash.online-convert.com/sha1-generator