The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> trying to make a password protected weblink
Roadhammer Gaming
post Jul 23 2015, 01:36 AM
Post #1





Group: Members
Posts: 4
Joined: 23-July 15
Member No.: 23,083



Hi, I'm trying to make a password protected weblink button, but the code doesnt seem to be invoking the java script, what am i doing wrong? heres the code i have, it seems to all work fine except it doesnt invoke the java script, i tried taking the argument away to test it and when invoking the script it still didnt go to the website

CODE

<script LANGUAGE="JavaScript"><!--
function codename()
{
if(document.name=formname)
{

  <a href="http://roadhammergaming.blogspot.com/p/downloads.html"></a>

}
}

//-->
</SCRIPT>

<form action="" method="" name="formname">

  <input type="text" name="textname">

   <input type="button" onclick="codename()" value="Submit">

    <input type="reset" value="Clear">

</form>


This post has been edited by Roadhammer Gaming: Jul 23 2015, 01:37 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 03:13 AM
Post #2


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



Try this instead… First off, instead of using

CODE

<input type="button" value="Submit">

Use this:
CODE

<input type="submit">


Also if you want to redirect, you can not use html code to redirect in a js script. Do this.

CODE



window.open("http://roadhammergaming.blogspot.com/p/downloads.html");

...


So you're final code in my opinion should be, if I get what you're meaning.

CODE

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script LANGUAGE="JavaScript"><!--
function codename() {
if(document.name=formname%26%2341%3B {

  <a href="http://roadhammergaming.blogspot.com/p/downloads.html"></a>

}
}

$(".form").submit(function(){
codename();
});
//-->
</SCRIPT>
</head>
<form action="" method="" class="form" name=%26%2334%3Bformname%26%2334%3B%26%2362%3B

  <input type="text" name=%26%2334%3Btextname%26%2334%3B%26%2362%3B

   <input type="button" value="Submit">

    <input type="reset" value="Clear">

</form>


This code basically, once the user submits the form, the javascript will redirect the user to the link.

This post has been edited by Mhatfield: Jul 23 2015, 03:13 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jul 23 2015, 06:52 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,649
Joined: 10-August 06
Member No.: 7



QUOTE(Roadhammer Gaming @ Jul 23 2015, 08:36 AM) *

Hi, I'm trying to make a password protected weblink button

You shouldn't use javascript for that, anyone can just look at the source and bypass it. The protected URL can also be freely shared. Use a serverside script like PHP or HTTP authentication instead. Sometimes the webhost support pages or control panels contain readymade solutions.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Roadhammer Gaming
post Jul 23 2015, 09:25 AM
Post #4





Group: Members
Posts: 4
Joined: 23-July 15
Member No.: 23,083



QUOTE(Mhatfield @ Jul 23 2015, 04:13 AM) *

Try this instead… First off, instead of using

CODE

<input type="button" value="Submit">

Use this:
CODE

<input type="submit">


Also if you want to redirect, you can not use html code to redirect in a js script. Do this.

CODE



window.open("http://roadhammergaming.blogspot.com/p/downloads.html");

...


So you're final code in my opinion should be, if I get what you're meaning.

CODE

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script LANGUAGE="JavaScript"><!--
function codename() {
if(document.name=formname%26%2341%3B {

  <a href="http://roadhammergaming.blogspot.com/p/downloads.html"></a>

}
}

$(".form").submit(function(){
codename();
});
//-->
</SCRIPT>
</head>
<form action="" method="" class="form" name=%26%2334%3Bformname%26%2334%3B%26%2362%3B

  <input type="text" name=%26%2334%3Btextname%26%2334%3B%26%2362%3B

   <input type="button" value="Submit">

    <input type="reset" value="Clear">

</form>


This code basically, once the user submits the form, the javascript will redirect the user to the link.


Thanks i will give that a try, i did try <input type="submit"> but it kept refreshing the page instead of going to the correct link so i used <input type="button"> instead then it didnt do anything lol
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Roadhammer Gaming
post Jul 23 2015, 10:03 AM
Post #5





Group: Members
Posts: 4
Joined: 23-July 15
Member No.: 23,083



I tried that and it didnt work at all, theres no place to type text in and the only button showing is the clear button, thanks for trying tho

anyone else have any ideas?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Jul 23 2015, 01:42 PM
Post #6


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



Please see the FAQ entry How do I password protect my web site?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 02:38 PM
Post #7


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



Yes you should use PHP, or another server-side due to the fact that it is open source and I can check the password in the source.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 02:51 PM
Post #8


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



Your previous code made absolutely no sense at all, to be frank.

(Before implementing code, make sure your host has Apache or a PHP server installed, like Apache.)

But If you really want a password protected site do this:

CODE

<?php
$Password = "Password"; //This is the correct Password
$PasswordUser = htmlentities($_POST['Password']); //This is the password that the user inputs, which is to be compared to the correct password.

if(isset($_POST) || $PasswordUser == $Password){
headers("Location: http://roadhammergaming.blogspot.com/p/downloads.html");
} else{
echo <<<Form
<form action="" method="post">
Password: <input type="password" name="Password" Placeholder="Password">
<input type="submit" value="Submit">
<input type="clear" value="Clear Input">
</form>
Form;
}
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 02:51 PM
Post #9


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



That simple code should be fruitful… wink.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 02:53 PM
Post #10


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



Yes the reason it kept refreshing the page is because you never specified an action in the action=""

action="" will just send the data to the current page, that is why.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Roadhammer Gaming
post Jul 23 2015, 04:33 PM
Post #11





Group: Members
Posts: 4
Joined: 23-July 15
Member No.: 23,083



ahh thank you very much, i did leave the action code out!! but my web host is blogger so calling javascript just doesnt work there so i had to do it this way:
CODE

<script type="text/javascript">
var password = "pizza";
var x = prompt("Please enter password "," ");
if (x == password) {
  alert("Password acepted");
  window.location = "http://roadhammergaming.blogspot.com/p/news.html";
}
else {
  alert("Retry");
  window.location = "http://roadhammergaming.blogspot.com/p/downloads.html";
}
</script>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 04:34 PM
Post #12


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



That works too, but still strongly suggesting seeing about using server-side…
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mhatfield
post Jul 23 2015, 04:36 PM
Post #13


Novice
**

Group: Members
Posts: 29
Joined: 22-July 15
Member No.: 23,063



If you implement code like that in your website, I could go there right now and check the source for password! If you are protected valuable merchandise, or products please consider something else. If it's not very valuable then, I guess this would work.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Jul 24 2015, 10:29 AM
Post #14


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



You might try to search for "password protect a page in blogger". Surely one of the results will be of help. As long as the password is not hardcoded and visible in any resource on your blog.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th April 2024 - 02:36 PM