Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-15-2015, 09:55 AM   #1
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Question Javascript help please

Ok, so I really need to brush up on my Javascript skills, which I have been actively doing.

This is what I need help with. I found a basic password prompt script that I have been using to keep script kiddies off of my page. I am not protecting anything too important, but I dont exactly want traffic. That having been said, I decided to go with this;
Code:
<SCRIPT language="JavaScript">
<!--hide

var password;

var pass1="cool";

password=prompt('Password!',' ');

if (password==password)
  {
Return;
}
else
{window.alert("Wrong!");
}
   {
    window.location="http://google.com";
    }

//-->
</SCRIPT>
The largest modification that I made, was to add "Return;" in place of the alert box that was there. I just want a quick and simple way to exit the code. In most cases, this works fine. However, in IE I get an error message. I will attach a screen cap at the end of this post.
That normally wouldnt be an issue, but I designed a portable app for windows that loads an IE object, then the site so that I dont leave the site in the history of computers that are not mine. (And also because I wanted to.) Another reason that I wish to fix this, is because I wish to learn. Eventually I will be slapping javascript into websites designed for the public, so I need to get back into the habbit.

That was a very long way of saying, that I wish to ask a simple question. I googled for ways to exit a javascript function, and the answer was to use "Return;". Does anyone here know a better way that will not upset IE?

Oh, and it should be noted that it only causes the error message when being ran from my program with the imbedded IE object. Not sure why that makes a difference, but the normal browser doesnt do that.

Thank you all for your time.

And of course, the screen shot...

__________________

__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 05-15-2015, 10:16 AM   #2
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,941
Default Re: Javascript help please

I don't see how this code will work since the line

if (password==password)

will always resolve to true. Is that line a typo? Shouldn't it read

if (password==pass1)?

Sorry, can't help with the Return issue.
__________________

strollin is offline   Reply With Quote
Old 05-15-2015, 10:24 AM   #3
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: Javascript help please

I am not sure, as I borrowed the code. All I know is, it works perfectly as is besides for the return issue. I can change the password==password to any password that I want. Example "password==yogi". Its just reading from the prompt and compairing to a preset. At least, that is the way that I have understood it. I am using "password==Jerry" right now. You know, keeping it simple.
I actually have no idea why they set it up as the following, as the pass1 variable is does not appear to be called on anywhere else in the script, but I know that it doesnt work at all if I dont leave it in.
Code:
var password;  
var pass1="cool";
I am just looking to replace return with somthing more along the lines of
"Application.ExitScript();". That is lua, and it does exactly what it says it does. I dont have to return an undefined value in lua. Oh, and if I define return, the script crashes completely.

And yeah, I see what you are getting at because in pretty much every other language, that wouldnt work. But in this case, it does. Meh, I have been out of the JS game too long.

Thank you for the quick reply btw.

EDIT
I also wish to clarify a few things.
First; When I say that I borrowed the script, I mean that I got it from a JS coding website that I am using to relearn what I once knew. I just modified the script to fit my needs. I suppose by defination that makes me a script kiddie, but that hardly fits the way I normally do things. Borrowing code is just somthing that I do on my way to learn. I do not make a habit of it.

Second; The unmodified version was using an alert prompt, but I find two prompts to get one thing done to be excessive and annoying. That is why I am looking for a way to simply stop the execution in its tracks. The alert box did that just fine, but again, it was annoying.

Third; Before anyone points out the obvious, of course I know that all someone would have to do to get the password is to view the source code. For the most part, the site is off the grid anyway. I just want to keep prying eyes away should some random person stumble upon it. I am not trying to keep anyone whom knows anything about coding out, as I already know that wouldnt work. I can use a JS encoder or somthing, but that would only slow someone down.
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 05-15-2015, 10:55 AM   #4
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: Javascript help please

Here is the exact script as I have it set right now...
Code:
<SCRIPT language="JavaScript"> 
<!--hide  
var password;  
var pass1="cool";  
password=prompt('Password!',' '); 
 if (password==Jerry)   
{ 
Return; 
} 
else 
{window.alert("Wrong!"); 
}    
{     
window.location="http://google.com";     
} 
 //--> 
</SCRIPT>
It prompts for a password, if correct exits. If wrong, redirects you to google. I can also have it loop back to the same page asking for the password again if I wish.

This works just fine everywhere with the acceptation of my app. Its driving me nuts because no matter what I change I get different errors, most of which crash the script before its allowed to even begin executing.
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 05-15-2015, 01:32 PM   #5
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,941
Default Re: Javascript help please

The way that script is written is correct, it's different than what you posted earlier.

However, instead of using

if (password==jerry), it is meant to be (technically it should be =="jerry")

if(password==pass1)

and if you want the password to be jerry, you should change the line

var pass1="cool";

to

var pass1="jerry";

otherwise, the pass1 variable is declared but never used and that line can be dropped entirely.
strollin is offline   Reply With Quote
Old 05-15-2015, 02:53 PM   #6
..m.0,0.m..
Site Team
 
iPwn's Avatar
 
Join Date: May 2010
Location: USA
Posts: 3,870
Default Re: Javascript help please

Code:
Return;
Should be:
Code:
return;
Coding is case sensitive. You're getting that error because it's now expecting a method that doesn't exist.

Also, you should NEVER hard code passwords. Some programmers might say this is okay, and for some languages it very well may be, but .NET is completely decompile-able. Meaning, anyone with a little bit of know-how will just look in your code and grab the password.

You'll want to use a web.config, and specifically an AppSettings container to store the password and pull from there. Then use encryption to secure that file.

See here.
__________________
Me: You'd think as the dominant species we wouldn't be so effing stupid.
J: We're just intelligent enough to be completely effing stupid.
iPwn is offline   Reply With Quote
Old 05-15-2015, 04:56 PM   #7
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: Javascript help please

Thanks guys!
@root: As I stated above in the thread, I am not to worried about most people getting the password. The page is hardly worth protecting. I am just using this as a launching platform to learn JS again, as its been years.
That being said, thank you for the link. I have bookmarked it for now.
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 06-01-2015, 01:56 PM   #8
Fully Optimized
 
Bahawolf's Avatar
 
Join Date: May 2005
Location: United States
Posts: 2,604
Default Re: Javascript help please

I suggest using Codecademy, if you're just brushing up on Javascript. It's an interactive training platform, and it's FREE (no catches). Among other languages, there is both a course on Javascript, and jQuery. It'll be helpful to cover the basics, and may help you out. :-)
Bahawolf is offline   Reply With Quote
Old 06-02-2015, 01:53 PM   #9
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: Javascript help please

Quote:
Originally Posted by Bahawolf View Post
I suggest using Codecademy, if you're just brushing up on Javascript. It's an interactive training platform, and it's FREE (no catches). Among other languages, there is both a course on Javascript, and jQuery. It'll be helpful to cover the basics, and may help you out. :-)
Thanks! I have no idea how this is the first time I have seen that site. Seems like it would be suggested more often.
That is yet another site to bookmark. I think I am going to start storing my bookmarked sites in a text file on GD or somthing.
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 06-02-2015, 04:41 PM   #10
Fully Optimized
 
Bahawolf's Avatar
 
Join Date: May 2005
Location: United States
Posts: 2,604
Default Re: Javascript help please

Quote:
Originally Posted by Draygoes View Post
Thanks! I have no idea how this is the first time I have seen that site. Seems like it would be suggested more often.
That is yet another site to bookmark. I think I am going to start storing my bookmarked sites in a text file on GD or somthing.
Yeah, it's a winner for sure! :-) The community are very helpful, and it's FREE. If you need any help or suggestions as you go along, feel free to send me a message!
__________________

Bahawolf is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:58 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0