storing user info/pass in web.config authentication

Posted by Tomaszewski on Stack Overflow See other posts from Stack Overflow or by Tomaszewski
Published on 2009-10-02T03:03:50Z Indexed on 2010/04/04 6:13 UTC
Read the original article Hit count: 489

Filed under:
|
|
|

Hello, I am trying to write a simple internal app with some simple authentication. I'm also trying to make this quick and learn about the forms authentication via web.config.

So i have my authentication working if I hard code my 'user name' and 'password' into C# code and do a simple conditional.

However, I'm having a tough time storing the a user/pass to be checked against in the web.config file.

The MSDN manual says to put this into the web.config:

<authentication mode="Forms">
    <forms loginUrl="login.aspx">
        <credentials passwordFormat="SHA1">
            <user name="user1" password="27CE4CA7FBF00685AF2F617E3F5BBCAFF7B7403C" />
            <user name="user2" password="D108F80936F78DFDD333141EBC985B0233A30C7A" />
            <user name="user3" password="7BDB09781A3F23885CD43177C0508B375CB1B7E9"/>
        </credentials>
    </forms>
</authentication>

However, the minute I add 'credentials' into the 'authentication' section, I get this error:

Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized element 'credentials'.

Source Error:

Line 44:     <authentication mode="Forms">
Line 45:       <forms loginUrl="login.aspx" />
Line 46:       <credentials>
Line 47:         
Line 48:       </credentials>


Source File: C:\inetpub\wwwroot\asp\projects\passwordCatalog\passwordCatalog\web.config    Line: 46

So my question is, how and where would I add the following in the web.config file?

<credentials passwordFormat="SHA1">
    <user name="johndoe" password="mypass123" />
</credentials>

© Stack Overflow or respective owner

Related posts about web-config

Related posts about authentication