Archived

This topic is now archived and is closed to further replies.

Java Script

This topic is 5313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Trying to setup a login page to a part of a Web-Page! I though Http Authentication was the best way.. its simple to implement but is kind of scary for the user when it appears.. I''ve seen Java Script can do the same thing and it looks a whole lot nicer! Do any of you know of any tutorials where i can learn to do this, found a few on the web but they want my CC details before they let you see them..... which i fair enough but cant aford it... if i could would have bought a book! Thanks for you help, Brian

Share this post


Link to post
Share on other sites
Well, I think you can probably make an external javascript file (.js), and place it like this:

<script src="MyJScript.js">
// Nothing goes in here
</script>

and you can create a function called Login(). It would be something like this:


  
function Login(user, pass)
{
if ((user == "Admin") && (pass == "Root"))
// Send user to authorized page

else // Incorrect

alert("Incorrect username or password!");
}


I hope this is what you wanted. BTW, you can use "else if" statements for multiple users:


  
if ((user == "User1") && (pass == "Pass1"))
// Send to authorized page

else if ((user == "User2") && (pass == "Pass2"))
// Send to authorized page

else // Incorrect

alert("Incorrect username or password!");

Share this post


Link to post
Share on other sites
Bear in mind you''ll never have a secure authentication if you use javascript.

I don''t know why you want to authenticate users, but if you''re using javascript anyone can authenticate as anyone else. Waste of time? I think so

HTTP authentication is the better option.

Share this post


Link to post
Share on other sites
You mean removing the statusbar, locationbar, etc..

self.menubar.visible=false;
self.toolbar.visible=false;
self.locationbar.visible=false;
self.personalbar.visible=false;
self.scrollbars.visible=false;
self.statusbar.visible=false;

Sorcerer


SorcSoft.com -> Homepage | Pictures | FTP Upload | Contact
ICQ: 201024198 | MSN: kleiwegl@hotmail.com

Share this post


Link to post
Share on other sites
There is a little gray box that pops up to take the used ID and password.

Rather than have this box i''d like to integrate it to the webpage or least be able to change the appearance of the box!

Share this post


Link to post
Share on other sites
If you have access to a server-side scripting language like ASP or PHP, you can use a session variable to check whether the user is authenticated or not. When your secure page(s) is processed on the server, check the session variable. If the user isn''t logged in, direct them to a simple HTML form that asks for the login info. If they have a valid username/password/whatever, set the session variable to say that the user has logged in.

Works beautifully.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Go with server side scripting. Run a search on User Authentication with PHP, or find an article at sitepoint.com (or another similar site). You can use another language if required, but I would recommend PHP if this is all you need it for, for it will be the simplest to pick up and the most readily available.

Share this post


Link to post
Share on other sites