Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question Simple HTML Password Prompt

    Hey All,

    Just wondering if anyone would be able to provide me with a simple HTML or Javascript code. Basically I want this.... if possible....

    As soon as you load the page a dialogue asking for a password (and username if necessary) appears before any content does. If the password is correct, the content appears, if not, nothing or an error msg comes up. But this all has to be done within the same page using only HTML and/or Javascript.

    It doesn't have to be 100% secure - just something to deter people who dont know the password. A tutorial would even be fine!

    Also - it doesn't have to be a popup msg, it could be like fields on the page - but it all has to be contained in 1 file.

    Thanks for any help!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Umm javascript is not the solution. It can be disabled and any passwords would need to be stored in the actual html page where anyone can see it. You need to use a server side language.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Actually... thanks for that but I just found something on another website in Javascript. Although it isn't the most secure it works okay for my purposes. But if, per say someone just turns off javascript for their browser can they get in?

    Code:
    <script language="JavaScript">
    <!--hide
    var password;
    var pass1="secretpassword";
    password=prompt('Enter Password To View Page',' ');
    if (password==pass1)
    alert('Correct password, click OK to enter.');
    else
    {
    window.location="http://www.msn.com";
    }
    //-->
    </script>
    Suggestions? Thanks!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    If JS was disabled the page wouldn't go anywhere but it wouldn't stop them from viewing the source of the page and finding the url to go to.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Ok - well it is all on the same page - so I guess that means it would just bypass the ask for password part and then just show them the page content?
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #6
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    A far better solution to your problem would be using HTTP Auth. Do you know what opperating system your web server runs as?
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #7
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Well - see normally I would use HTTP or PHP to validate via encrypted MySQL data to secure a site really well but this script is just for my google Blogger account. Seing as they don't offer any type of password protection I have to be creative while limited to a .html file. Any other ideas?

    And once again, if they have javascript disabled and the script is on the same page - will it just bypass the login part and reveal content?

    Thanks!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #8
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Most people who do not want people to see their blog - do not post a blog on the internet.

    Javascript is the only way to go in your situation, however - if people do indeed have javascript disabled, yes, they will see your content.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #9
    New Coder
    Join Date
    Dec 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be best to use HTTP Auth, so you could possibly host the Auth file and the pass-protected page on a server, if you can find a free one to do so. However, using javascript, you could store it in a .js file and put the javascript code in that. It still wouldn't be really secure, but it would deter anyone who doesn't really want to see the page or know how to check the .js file.

    With Javascript disabled I don't think anything would happen at all. It wouldn't execute the code to switch to the new page.

  • #10
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    You cannot host .htaccess files offsite for security reasons. Besides, blogger would never load it.

    If you are going to go ahead with your javascript idea, I suggest you hash the password, and then hash the input, then compare the hashes, that will at least prevent people getting around your password.

    If you base64 the urls, it will further confuse the average noob. Thing is, for it to be sucessfull, you should redirect to the correct page - which this script does not do. With this script, if you do not have Javascript enabled, you will just see the normal page.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #11
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Sounds like a good idea.... but even if they do want to try and "hack" their way past... the password prompt continually comes up until you input the right pass anyways.....

    But how would I hash the password and etc. of the code shown in the second post of this thread? And I don't even know what "base64" the urls means...?

    Thanks Again!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #12
    New Coder
    Join Date
    Aug 2006
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have a look here

    http://www.javascriptkit.com/script/cut76.shtml

    obviously people will be able to get through to the blog if they look at the html, but other then redirecting to a different page with php then redirecting to another blogger account, i dont see many other ways...

  • #13
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool

    Quote Originally Posted by Troy297 View Post
    Actually... thanks for that but I just found something on another website in Javascript. Although it isn't the most secure it works okay for my purposes. But if, per say someone just turns off javascript for their browser can they get in?

    Code:
    <script language="JavaScript">
    <!--hide
    var password;
    var pass1="secretpassword";
    password=prompt('Enter Password To View Page',' ');
    if (password==pass1)
    alert('Correct password, click OK to enter.');
    else
    {
    window.location="http://www.msn.com";
    }
    //-->
    </script>
    Suggestions? Thanks!

    Here, when the page opens the user can click CANCEL and the prompt will close letting everyone in!

  • #14
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jolimk View Post
    Here, when the page opens the user can click CANCEL and the prompt will close letting everyone in!
    You can make this stop happening by adding a function in when the password is wrong, such as loading another page. This also means that when the cancel button is pressed, the fail page is loaded, for instance:

    Code:
    <script language="JavaScript">
    <!--hide
    var password;
    var pass1="24499045";
    password=prompt('Enter Password To View Page',' ');
    if (password==pass1)
    {
    window.location="http://www.msn.com";
    }
    else if (password!=pass1)
    {
    window.location="fail.htm";
    }
    //-->
    </script>
    I don't know if this line:

    Code:
    alert('Correct password, click OK to enter.');
    only works on some browsers, but I removed it, since it doesnt even show up in Firefox at any point, it just goes automatically to the window.location

  • #15
    New to the CF scene
    Join Date
    Feb 2014
    Location
    oklahoma city
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here try this it use html for a pass word as a login. like log in a 2nd page.
    <!DOCTYPE html>

    <p>Click the button to the prompt the login box.</p>

    <button onclick="myFunction()">Login</button>

    <p id="demo"></p>

    <script>
    function myFunction()
    {

    var location;
    var password;
    var name=prompt("Please enter your password","password");

    if (name!=null)

    {
    location= name + ".html";
    root=window.location.href=name +".html";
    root.location.href = location;
    } else {
    location.href = location;
    }
    }
    </script>


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •