Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:25:27+00:00 2026-06-18T08:25:27+00:00

I have a quick question. In my code, I have this: if(!(username.IsEmpty() || password.IsEmpty()))

  • 0

I have a quick question. In my code, I have this:

if(!(username.IsEmpty() || password.IsEmpty()))
    {
        if (WebSecurity.UserExists(username) && WebSecurity.GetPasswordFailuresSinceLastSuccess(username) > 4 && WebSecurity.GetLastPasswordFailureDate(username).AddSeconds(120) > DateTime.UtcNow) 
        {
            Session["gActionMessage"] = "You're account has been locked due to too many failed login attempts. " +
                                            "Please try again in 2 minutes.";
            Session["gActionMessageDisplayed"] = "not";
            Response.Redirect("~/");
            return;
        }

        if(WebSecurity.Login(username, password, false))
        {
            errorMessage = "";
        }
    }

    if (!WebSecurity.IsAuthenticated)
    {
        errorMessage = "You are no longer logged in. Please supply your username and password credentials along with the rest of the form data.";
    }

When I attempt to use this code (the check right after the login is actually within an if(IsPost), so that I can check whether the user is still logged in before using the posted data. When it fails the check “if(!WebSecurity.IsAuthenticated)” for the first time, a small section of the page opens up, asking for login information. Once reentered and re-posted, the check reads the value of “username” and “password” and attempts to re-log them in. It does just that, however directly after they are supposed to be “logged in” it passes the “if(!WebSecurity.IsAuthenticated)” branch and executes its contents. Am I checking the “if(!WebSecurity.IsAuthenticated)” to soon? Does the page have to finish loading before a person is actually considered authenticated?

I just can’t seem to pinpoint why this is happening and haven’t been able to find any help in research either.

Thanks, everyone, for any help!

UPDATE:

I have posted the code that appears below the code above, below:

if((Roles.IsUserInRole((WebSecurity.CurrentUserName), "Locked")) || (Roles.IsUserInRole((WebSecurity.CurrentUserName), "AdminLocked")))
    {
        Session["gActionMessage"] = "Your account is locked. ";
        Session["gActionMessage"] += "Please contact an administrator and ask that your account be approved.";
        Session["gActionMessageDisplayed"] = "not";
        Response.Redirect("~/");
    }
}
}

@RenderPage("~/Shared/HeaderLayout.cshtml")

        <div>
            <span><button type="button" class="btn" onclick="location.href='/IntroPage.cshtml'">Main Page</button></span><span class="heading">Lookup Entry</span><span><button type="button" class="btn" onclick="javascript:document.getElementById('searchForm').submit()">Search</button></span></br></br>
            <span style="font-size: 3em; color: #808080;">________________________________________________</span></br></br></br>
        </div>

        <div id="FormHolder">
            <form id="searchForm" class="searchForm" method="post" action="">
        @{
            if (errorMessage != "")
            {
                <div class="errorMessageWrapper"><span style="font-style: italic; font-weight: 700;">ERROR:</span><br/>@errorMessage<br/><br/>
                    @if(!WebSecurity.IsAuthenticated && success==false)
                    {
                        <table class="accInterfaceTable">
                            <tr>
                                <td class="accInterfaceLabelCell">
                                    <label for="username">Email:</label>
                                </td>
                                <td class="accInterfaceInputCell">
                                    <input type="text" id="username" name="username" /><br/><br/>
                                </td>
                            </tr>
                            <tr>
                                <td class="accInterfaceLabelCell">
                                    <label for="password">Password:</label>
                                </td>
                                <td>
                                    <input type="password" id="password" name="password" /><br/><br/>
                                </td>
                            </tr>
                        </table><br/><br/>
                        <input type="hidden" id="hiddenLoginSubmit" name="hiddenLoginSubmit" value="" />
                        <input type="submit" class="btn" value="Log In" />
                    }
                </div><br/>
            }
        }
                <table class="searchTable">
                    <tr>
                        <th>Search Field<br/><br/></th>
                        <th></th>
                        <th>Search Condition<br/><br/></th>
                        <th></th>
                        <th>Search Parameter<br/><br/></th>
                    </tr>

There is more html below this, but it is just a redundant html form.

UPDATE2:

Well, I never did find a reason why the “if(!WebSecurity.IsAuthenticated)” branch is executed directly after an explicit “if(WebSecurity.Login(username, password, false))” branch is executed, however I was able to tie in a separate local boolean variable to the logic and everything is working fine now (I checked to make sure it will always check unless JUST signed in with the branch above, and checked to make sure it does in fact log in, etc.).

If anyone could tell me why this was happening for the benefit of my (and anyone else who comes across this page and has run into a similar problem) education, I will gladly accept the answer.

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:25:28+00:00Added an answer on June 18, 2026 at 8:25 am

    I remember reading on MSDN or someplace, the WebSecurity.IsAuthenticated does not work until the page is fully loaded. Meaning if you login a user in a page and in the same flow of code you check IsAuthenticated, it will NOT return True. For IsAuthenticated to be True the page has to be reloaded or use the better practice; which is to redirect the user to another secured page as soon as the login is successful and in that page check IsAuthenticated.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question, What have I done wrong here. The purpose of this code is
I have a quick Jquery question .. This Jquery code is supposed to show
Another quick question here, I have this code: string sa[6] = { Fort Sumter,
Another quick question if anyone is up to it. I have this code: for(int
I have quick question: this code snippet works: NSArray *permissions = @[@email, @user_birthday]; return
quick question really: I have this code: using System; using System.Collections.Generic; using System.Linq; using
I have a quick question: Somebody have a code snippet to hide a window
I have a quick question about altering the build path as the code is
i have what i hope is a quick question about some code i am
Quick question about include/requre_once . I have some code that is common to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.