Authentication through web.config not authenticating in 3.5

This is one of this things that should be extremely simple and I just can’t work out why it’s not working.

I’m trying to set up some very quick authentication for an 3.5 app but storing the usernames and passwords in the web.config file (I know it’s not very secure but it’s an internal app that I keep getting asked to add and remove logins for so this is the quickest way to do it).

So, the relevant config section looks like this:

<authentication mode="Forms">
   <forms loginUrl="~/login.aspx">
     <user name="user" password="password" />
     <user name="user2" password="password2" />

    <deny users="?"/>

And, in the login page, the code look like this:
string username = tbUsername.Text;
string password = tbPassword.Text;

if (FormsAuthentication.Authenticate(username, password))
    FormsAuthentication.RedirectFromLoginPage(username, false);

But, FormsAuthentication.Authenticate(username, password) always returns false. And I can’t figure out why.

I even tried using Membership.ValidateUser but that just adds in a local database to the App_Data folder.

Is there something really basic I’m forgetting here or does this not work at all in .net 3.5?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I’m not sure if this has changed in .NET 3.5, but the <credentials> element has an attribute passwordFormat that defines the format for passwords in the web.config. From the MSDN documentation for .NET 3.5, the default format is SHA1.

If you’re using cleartext usernames and passwords in your web.config, you should use:

<credentials passwordFormat="Clear">

Event though this is an internal application I’d still recommend at least hashing the password instead of leaving it in clear text.

Method 2

I think the reason is because you did not indicate the passwordFormat.

Default is SHA1, hence your clear text in fact not used properly.

Method 3

You have to specify <credentials passwordFormat="Clear"> when you store password in clear text.

The alternatives are encrypted passwords using MD5 or SHA1.

See for a function to encode a password.

You might also consider using some of the available user controls that does a lot for you automatically. Look under the “Login” section in the control toolbox in Visual Studio.

The following page will provide everything you need for this simple case, and the looks of the Login control is fully customizable:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        e.Authenticated = FormsAuthentication.Authenticate(Login1.UserName, Login1.Password);

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate">

Method 4

Another possible pitfall that is that the user name “Admin” appears to be special and not honored if your testing a credential set in web.config

 <user name="Admin" password="somepassword" />  //Authentication always returns false for me

 <user name="MyName" password="somepassword" />  //Authentication works normally 

The problem doesn’t seem to apply in your case, but I just spent an hour figuring that out so I thought I’d record it here.

Method 5

i find that solution……..first you have to get hashvalue by using FormsAuthentication.HashPasswordForStoringInConfigFile(“abc”,”SHA1″) in text box by running your program and then provide this value in

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x