Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i Javascripts

Status
Not open for further replies.

Ghostrider

Programmer
May 3, 1999
4
AU
How do i make a password Javascript for Netscape composer.
 
Well, for starters: I REALLY don't suggest that you use Netscape Composer for JavaScripting. It REALLY wasn't made with that in mind.<br>
<br>
A MUCH better application for writing pages that contain JavaScript would be your "Notepad" program (accessible through: Start;Programs;Accessories;Notepad)<br>
<br>
As far as the actual creation of the JavaScript itself, you would probably want to make a script that looks sorta like this (there are other, possibly better, ways, but they are harder to explain):<br>
<br>
&lt;script language=javascript&gt;<br>
&lt;!--;<br>
<br>
var checkpass=ask_entrance();<br>
<br>
function ask_entrance()<br>
{<br>
var uid=prompt("What's your username?",'');<br>
var pass=prompt("What's your password?",'');<br>
<br>
if(uid=="user1" && pass=="password1")<br>
{<br>
//Insert whatever you want to be password protected //between these "curly braces" "{}"<br>
document.writeln('Hello '+uid+' your name and password have been verified!');<br>
alert("Hello "+uid+" your login has been successful!");<br>
//You can repeat the "}else{" and "if()" clauses for //however many mambers/passwords you have.<br>
}else{<br>
if(uid=="user2" && pass=="password2")<br>
{<br>
//Same as for last, insert any password protected info //for user2 here<br>
}else{<br>
alert("I'm sorry, your username/password authentication failed, please try again");<br>
ask_entrance();<br>
//Remember to add the appropriate # of end braces "}" for //the number of begin braces "{", or your script won't //function properly.<br>
}}}<br>
<br>
//--&gt;<br>
&lt;/script&gt;<br>
<br>
<br>
I hope this script serves you well!<br>
<br>
-Robherc<br>
<br>
Fell free to contact me if you have any more questions.<br>
E-mail: robherc@netzero.net<br>
ICQ#: 34916735
 
Thanks for the script. It looks like a useful one and I'll be trying to implement it, but I'm running into a snag...<br>
<br>
Whenever I open the page I can get the prompts, and then Netscape 4.5 gives me a javascript error.<br>
<br>
I typed it in as written (minus some commentary). What else do I do? I placed the following in my &lt;head&gt; code. Adding onload="ask_entrance()" to the &lt;body&gt; tag just cycles the prompts twice before the error.<br>
<br>
&lt;script language="JavaScript"&gt;<br>
&lt;!-- Hiding the code from non-java enabled browsers<br>
<br>
var checkpass=ask_entrance();<br>
<br>
function ask_entrance()<br>
{<br>
var uid=prompt("What is your username?",'');<br>
var pass=prompt("What is your password?",'');<br>
<br>
if (uid=="user1"&& pass=="password1")<br>
{<br>
//Insert whatever you want to be password protected here:<br>
{password.htm}<br>
document.writeln('Hello '+uid+', your name and password have been verified');<br>
alert("Hello "+uid+", your login has been sucessful!");<br>
//You can repeat the "}else{" and "if()" clauses for as many users and passwords as needed<br>
}else{<br>
if (uid=="user2"&& pass=="password2")<br>
//Insert more users here using else<br>
{<br>
}else{<br>
alert("I'm sorry, your username/password authentication failed, please try again");<br>
ask_entrance();<br>
}<br>
}<br>
}<br>
<br>
// End of hiding --&gt;<br>
&lt;/script&gt;<br>
<br>
Thanks for any help.<br>
<br>
-Eric
 
Nevermind...<br>
<br>
Just solved my little problem. I had to change the following from:<br>
<br>
//Insert whatever you want to be password protected here:<br>
{password.htm}<br>
document.writeln('Hello '+uid+', your name and password have been verified');<br>
<br>
to:<br>
<br>
<br>
//Insert whatever you want to be password protected here:<br>
document.writeln('Hello '+uid+', your name and password have been verified');<br>
<br>
Now there's no problems and it's a darn nice script too if I may add...
 
Just one quick suggestion; I think I know what you're trying to do here :)<br>
<br>
Try inserting the line:<br>
window.location.replace(password.htm);<br>
<br>
between the lines:<br>
//Insert whatever you want to be password protected here:<br>
&<br>
document.writeln('Hello '+uid+', your name and password<br>
have been verified');<br>
<br>
If you're wanting it to automatically forward visitors with valid logins to a "password.htm" page.<br>
<br>
<br>
Please let me know if this helps,<br>
-Robherc
 
Actually, this now works fine as it stands with just a password protection on a page and no forwarding. I can't access anything on the page without first getting past the password. <br>
<br>
I will try inserting <br>
window.location.replace(password.htm);<br>
this afternoon sometime to see if that will help forward.<br>
<br>
Thanks for all the help.<br>
-Eric
 
Ghostrider-<br>
<br>
Did Gribo's (Eric's() and my conversation help to solve your problem with the script? Or will you still need me to rewrite it for you?<br>
<br>
<br>
-Robherc
 
I'm sorry, but am I missing something here? What is to keep someone from simply viewing the source and looking at the javascript to get the password(s)?
 
Well, that IS a possibility, but it isn't VERY likely that many ameture viewers would know how.....it won't let you load the page at all unless you enter a correct password. This makes it EXTREMELY hard to just view source and get the passwords. The only way that I currently know of to steal the passwords is one that I made up myself & WILL NOT disclose...but it works with CGI password submissions & everything but cookie-only, certificate, or SSL entry methods.<br>
<br>
<br>
-Robherc
 
Robherc<br>
<br>
No can you please rewrite it for me because that isn't the problem i had and i tryed that on the system i am using. <br>
<br>
If you wish to contact me more quickly you can email me on <br>
startrek87@hotmail.com or blogs@startrekmail.com<br>
<br>
Trek87
 
Trek87-<br>
<br>
OK, I will try to re-write it for you, I can't guaruntee when I'll be able to finish it though as I'm currently extremely busy during my 'net time; wi'll try to get it made for you if possible.<br>
<br>
<br>
-Robherc
 
Oh take your time i haven't got to finish the site for uploading for anouther 5 weeks.<br>
<br>
Trek87
 
Having read your responses it seems that my query is rather simple. I am new to programming and have started by putting together a very simple script which produces a mouseover effect. The detailed files are in the local folder. I cannot get it to run. Not sure where to go next. Could you help?<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;script&gt;<br>
&lt;!--<br>
&lt;script language="JavaScript"&gt;<br>
{<br>
buttonon = new Image;<br>
buttonon.src = "bronzefish.gif";<br>
buttonoff = new Image;<br>
buttonoff = "bronzefish_plus.gif";<br>
}<br>
function img_act(imgName)<br>
{<br>
imgOn = eval(imgName + "on.src");<br>
document
.src = imgOn;<br>
}<br>
function img_inact(imgName)<br>
{<br>
imgOff = eval(imgName + "off.src");<br>
document
.src = imgOff;<br>
}<br>
//--&gt;<br>
&lt;/script&gt;<br>
&lt;/head&gt;<br>
&lt;body&gt;<br>
&lt;a href= " Mouseover="img_act('button'); return true;" on Mouseout="img_inact('button'); return true"&gt;&lt;img src="bronzefish_plus.gif" border=0 name="button"&gt;&lt;/a&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
 
bluefish-<br>
you simply forgot to insert ".src" after "buttonoff".<br>
{<br>
buttonon = new Image;<br>
buttonon.src = "bronzefish.gif";<br>
buttonoff = new Image;<br>
buttonoff&lt;====&gt; = "bronzefish_plus.gif";<br>
^<br>
right there,<br>
see what I mean?<br>
<br>
-caseyc<br>

 
Thank you Caseyc. You have restored my faith in human nature and made a very dull day bright again.<br>
bluefish
 
I have put.src in and tried everything else I can think of but it still doesn't work. Any ideas?
 
You might want to try the following. I've used it in numerous pages without any trouble. All I did was replace my graphics with yours.<br>
<br>
Place this in the &lt;head&gt; of your code:<br>
<br>
&lt;!-- Hiding the code from non-java enabled browsers<br>
<br>
function locate () {<br>
}<br>
<br>
if(navigator.appVersion.substring(0,1) &gt;=3) {<br>
var cache_sample = new Image ();<br>
cache_sample.src = "bronzefish_plus.gif";<br>
}<br>
<br>
function live_change(dummy) {<br>
if(navigator.appVersion.substring(0,1) &gt;=3) {<br>
<br>
if (dummy == "sample") {<br>
together_normal = new Image();<br>
document.sample.src=together_normal.src = "bronzefish.gif";<br>
}<br>
if (dummy == "sample_active") {<br>
together_active = new Image();<br>
document.sample.src=together_active.src = "bronzefinsh_plus.gif";<br>
}<br>
<br>
}<br>
}<br>
// End of hiding --&gt;<br>
<br>
&lt;/script&gt;<br>
<br>
<br>
And then place this in the &lt;body&gt; of your page where you want the link:<br>
<br>
&lt;a href=" onMouseOver="live_change('sample_active')"<br>
onMouseOut="live_change('sample')"&gt;&lt;img src="bronzefish.gif" name="sample" border="0" &lt;/a&gt;<br>
 
Yeah, you also have a space between 'on' and Mouseover. It Your script should work fine if after putting the '.src' in the appropriate place and making 'on Mouseover=' into all one word like 'OnMouseOver='
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top