Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Everyone,

I am creating a small website which i am gonna placed on Local shared drive.

I have Created a Simple Login Page using Javascript Code as Follow:

C#
function check(form)
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.userid.value == "admin" && form.pswrd.value == "pwd@123")
{
window.open('home.html')/*opens the target page while Id & password matches*/
}

else if(form.userid.value == "maddy" && form.pswrd.value == "maddy@123")
{
window.open('home.html')/*opens the target page while Id & password matches*/
}

else
{
alert("Please Enter Username and Password")/*displays error message*/
}
}


But problem occurred here, I have Shared Login Page link to every one, when they logged in with defined username and Password they go to home page which opens in new Window Which i don't want.

1) I want to open "home.html" in same window.

and

If someone directly entered the "home.html" url then they can see the homepage without any valid login.

2) To open homepage everyone must enter username and Password else they can not access the homepage with direct link.

Please suggest me with Javascript, Jqueries, HTML,CSS and bit easy tricks as i am uploading this web on Local Shared drive.

Thanks and Regards,
Mayur K. Alaspure
Posted

Gday mate.

Sounds like you're just doing a home-project, type thing - i.e all machines in same building/residence - not something to be accessed from the outside world.
In either case, it's really something that you need a webserver(software) for. That way, you have the file 'home.html' (or another equivalent file) sitting on the server. When it's requested, the server examines it and executes any code in it before returning a result to the requester (usually a web-browser).

With that said, the answer to (1) is to set the location of the current window, rather than opening a new one. You can do this by setting window.location, instead of using window.open.

My answer to question (2) would be to download XAMPP then do a login-page tutorial. Then, your users' names/passwords will be submitted to a page on the web-server that checks their validity before passing them on to the main file, or reloading the login page. Since you've got active code in the home(.html) page, you can check if the user is logged in or not. If not, just don't output any of the concerned page.

This brings up another point - anyone with a link to the login page can view it's source. When this is done, the passwords/usernames for everyone will be visible. This is really not such a good system..

You can get XAMPP here: http://www.apachefriends.org/en/xampp-windows.html[^]
Here's a tute that looks good: http://www.phpeasystep.com/phptu/6.html[^]
 
Share this answer
 
Comments
Mayur2258 27-Aug-12 10:36am    
Thanks a Lot for your help... :)
Regards,
Mayur Alaspure
Take a look at this question[^] and the links that are in it.

It will explain you some concerns related to it.

Good luck!
 
Share this answer
 
Comments
Mayur2258 27-Aug-12 10:37am    
Thanks a lot for your help...
This article is great..
Regards,
Mayur Alaspure
Joan M 27-Aug-12 10:41am    
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900