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 7033175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:01:52+00:00 2026-05-28T01:01:52+00:00

I stumbled across a simplistic, but helpful way to password protect a page here:

  • 0

I stumbled across a simplistic, but helpful way to password protect a page here:
Pop up password protect

Here’s the code:

<%

needAuthentication = True

If Request.Form.Count > 0 Then 
    If Request.Form("username") <> "jon" Or Request.Form("password") <> "secret" Then
        ' Redirect to another URI
        Response.Redirect("/")
        Response.End
    End If
    needAuthentication = False
End If

%>
<html>
<body>
<%

If needAuthentication Then

%>
<form method="post" action="thenameofthepage.asp">
  <div>Username: <input type="text" name="username" /></div>
  <div>Password: <input type="text" name="password" /></div>
  <div><input type="submit" value="Submit" /></div>
</form>
<%

Else

%>
<p>Page content here</p>
<%

End If

%>
</body>
</html>

Two questions:
1) How can I improve this that when the password fails it calls an alert box “Login Failed” and resets the form?
2) How insecure is this? Are there ASP methods to improve security?

A few notes:
No database involved — this is just a page protected by one global password.
And, if you couldn’t already tell, my ASP skills are non-existent. Thanks in advance.

UPDATE: (alert working with failed login but page content loading anyway)

<%
needAuthentication = True
authenticationFailed = False

If Request.Form.Count > 0 Then 
    If Request.Form("password") <> "secret" Then
        authenticationFailed = True
    End If
    needAuthentication = False
End If

%>


<html>
<body>

<%
If needAuthentication Then

%>

<form method="post" action="passwordtest.asp">
  <div>Password: <input type="text" name="password" /></div>
  <div><input type="submit" value="Submit" /></div>
</form>

<%
Else

%>

<p>Page content here</p>

<%
End If

%>

<%
If authenticationFailed Then

%>

<script type="text/javascript">
  alert("Invalid login");
</script>

<%
End If
%>

</body>
</html>
  • 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-05-28T01:01:52+00:00Added an answer on May 28, 2026 at 1:01 am

    You would do something like:

    authenticationFailed = False

    And then in the Else section of your statement, set authenticationFailed = True.

    Then on your page have something like:

    <%
    
    If authenticationFailed Then
    
    %>
    <script type="text/javascript">
      alert("Invalid login");
    </script>
    <%
    

    Security has many elements. Assuming you can keep the password secret, and assuming no one else can get their hands on this file, then so long as you access the site using HTTPS you should be fine 🙂 – note that was a lot of “ifs” there.

    If you want to know more about security, I would recommend googling the subject. Security is directly related to the technology you’re using – although different technologies do try and make things easier in their own ways.

    Oh and one additional thing – this method of logging in requires that you login every time you want to access a protected page. It doesn’t remember it as you might expect. You’d need to investigate sessions for that – which is a topic all in itself: http://www.w3schools.com/ASP/asp_sessions.asp.

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

Sidebar

Related Questions

I stumbled across a code based on unions in C. Here is the code:
I have stumbled across some code that is adding strings to a List but
I stumbled across this code and am too proud to go and ask the
I stumbled across this C code today. Can anyone tell me what the 'where'
I just stumbled across this bug in some legacy code: class MyAPIHandler { private:
I recently stumbled across DBslayer ( http://code.nytimes.com/projects/dbslayer/wiki/WhyUseIt ) and wondered what is the actual
I was browsing my teacher's code when I stumbled across this: Order* order1 =
I was looking at some existing code and stumbled across a variable declaration I
I was calculating the Fibonacci sequence, and stumbled across this code, which I saw
I stumbled across a post on here regarding connecting to a DB with JavaScript.

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.