• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

(Probably) Need Help with Javascript

Inept At Normal

New member
OK. So.

I'm wanting to make a blog of sorts. I want it to be private, open only to others to whom I specficly want to read it. This means, that in the front page, I want to make a bit of code; a password field. If they get the password right, the code will take them to te actual blog. If they get it wrong, the page refreshes (or sometging pops up to tell them they're wrong.)

I know that Javascript, in theory, would work for this. The problem is, I only know how Javascript generally works and not how to use it.

I was wondering if you guys could help me come up with a little bit of code that would make this work. I was trying to do it myself with information gathered from w3 schools, to no avail. Any clue?
 
Because Javascript is client-side, any Javascript code you write - including any password you check the user-entered string against - will be visible to any user who knows where the "View Source" option is. Javascript won't provide any security worth mentioning in this regard.
 
:3 I know. It's something I'm doing for my dad to make him feel better about it. He doesn't know much about computers.

I want something that looks safe. It doesn't nessasarily have to actually be effective.
 
Whether or not he actually "knows much", is it actually really important that no one without a password can read it? If it's a simple, small, personal site that isn't necessarily going to contain anything super-sensitive then I guess that would work, but anything more than that and you'd want something more serious. Very basic server-side password protection is simple enough, but that would depend on the server the blog is to be hosted on. Does it have PHP, Python, Perl...?

Alternatively, you might just be better off having him use something like WordPress and either making the posts private or password-protecting any posts he doesn't want widely read.
 
Oh, no no no. I don't think you understood what I was saying. (Because I'm terrible at explaining things! Admit it.)

This blog is a personal site of mine. Dad's afraid that all of you seventy-two year old stalkers are going to read it and some how deduce where I live. Thus, to give him some peace of mind, this is what I wanted to do.

I do actually have PHP, but I'm absolutely terrible with it and can only do the simplest of tasks. I am really seriously OK with the client-side JavaScript.

I may actually decide to switch to Wordpress, but I'm actually pretty proud of my homemade blog site and I'd like to keep it that way if at all possible. Thanks for the suggestion, though.
 
I'm kind of rusty with Javascript and HTML and feel free to correct me if I'm using some sort of poor form or something, but this should serve your purposes if you really want to use Javascript and don't care about it actually being secure or not.

Code:
<script type="text/javascript">
<!--
function checkPassword(input)
{
	if (input=="your password here")
	{
		window.location = "http://www.dragonflycave.com";
	}
	
	else
	{
		alert("whatever error message");
	}
}
-->
</script>

And then put this in your body:

Code:
<form name="whatever" action="#">
<input name="password" type="text" value="default text" />
<input type="button" value="button text" onClick="checkPassword(password.value);" />
</form>

It'll just give you a text field to enter the password in and a button. You'll want to prettify that obviously and change variables and such to something other than "whatever".
 
Back
Top Bottom