NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Simple Complete Script To Password Protect An Area On Your Site

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-08-2007, 12:07 PM THREAD STARTER               #1 (permalink)
Account Closed
Join Date: Jul 2007
Posts: 349
mike1023 will become famous soon enoughmike1023 will become famous soon enoughmike1023 will become famous soon enough
 



Simple Complete Script To Password Protect An Area On Your Site


Hi,

I thought I would post a simple method to password protect an area on your website and include the files needed.

This can easily be done client side using JavaScript, however be aware that this should not be used for transactions and areas that should be forbidden in a heavy manner. The best use of this script is for a generic area that should be protected.
????: NamePros.com http://www.namepros.com/code/382647-simple-complete-script-password-protect-area.html

You can copy and paste the form anywhere you want in your page to provide the "user" and "pass" form. Edit the script where it is noted and change the URLs for the redirect pages.
--------------------------------------------------------------------------
Code:
<form>
<p><span class="formtextstyle">Enter User Name: </span><span class="formaccent">*</span>
 
    <input name="text2" type="text" class="formstyle" value="Login" size="20" maxlength="10"> 
    <span class="formtextstyle">Enter Password:</span>
    <span class="formaccent">*</span>    
<input name="text1" type="password" class="formstyle" value="password" size="20" maxlength="10"> 
  <input name="Submit" type="button" class="formstyle" onclick=javascript:validate(text2.value,"user",text1.value,"pass") value="Go  &gt;&gt;" > 
  
  <!-- changing the words "user" and "pass" above will modify the user name and password for login.-->
</p>
</form>
<script language="javascript">

function validate(text1,text2,text3,text4)
{
 if (text1==text2 && text3==text4)
 load('success.html'); <!--This is your page that the user is taken to when they have entered the correct login information. You can change it to whatever you want.-->
 else 
 {
  load('failure.html'); <!--This is the page the user is taken to when they have entered the incorrect login information. You can change it to whatever you want.-->
 }
}
function load(url)
{
 location.href=url;
}
</script>
--------------------------------------------------------------------------
Thats it! Enjoy!
Last edited by SecondVersion; 10-08-2007 at 07:57 PM.
mike1023 is offline  
Old 10-08-2007, 12:20 PM   #2 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
I don't mean to be rude but Javascript for a secure area is suicide .
Daniel is offline  
Old 10-08-2007, 12:22 PM   #3 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
Anyone considering using this should be warned that it can be bypassed by anyone who knows how to view the html source of a page.
__________________
NameCooler.com
-NC- is offline  
Old 10-08-2007, 12:27 PM THREAD STARTER               #4 (permalink)
Account Closed
Join Date: Jul 2007
Posts: 349
mike1023 will become famous soon enoughmike1023 will become famous soon enoughmike1023 will become famous soon enough
 



right on i agree! Maybe i didn't make my warning clear enough on it :-|

Everyone please know that this is ALL client side so anyone with knowledge of pretty much anything development related could look at the source and see the code to enter the access area.

I would only use it for friendly sites that are not needed to be protected in a "unaccessible" way. Otherwise use a server side script PHP or something similar.
mike1023 is offline  
Old 10-08-2007, 12:38 PM   #5 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Here's a half-assed attempt by me. You'd need to check on the page it goes to that the details are correct.

PHP Code:
<?php 

define
("ADMIN""danltn");
define("PASSWORD""password");
define("CORRECTPAGE""randomfile.php");
????: NamePros.com http://www.namepros.com/showthread.php?t=382647

$page $_SERVER['PHP_SELF']; 
if(isset(
$_GET['out'])) { setcookie("pass","NULL"); setcookie("admin","NULL"); header("Location: $page"); exit();  }
if(isset(
$_POST['pass'])) { setcookie("pass",md5($_POST['pass'])); setcookie("admin",md5($_POST['admin'])); header("Location: $page?fail"); }
????: NamePros.com http://www.namepros.com/showthread.php?t=382647
if(
$_COOKIE['pass'] == md5(PASSWORD) && $_COOKIE['admin'] == md5(ADMIN)) { header("Location: ".CORRECTPAGE); } 

?>
<div align="center">
<div style="width:400px;background-color:#DDA;padding:25px;" align="center">

<form action="login.php" method="POST">
<h1 style="font-size:20px;">Login</h1>
<?php if(isset($_GET['fail'])) { echo '<span style="padding:10px;"><u>Username</u> or <u>password</u> were incorrect.</span> <br /><br />'; } ?>
Username: <input style="font-size:18px;" type="text" name="admin" /><br /><br />
Password: <input style="font-size:18px;" type="password" name="pass" /><br /><br />
<input type="submit" name="submit" value="Login"  style="font-size:18px;" />
</form>
</div>
</div>
Daniel is offline  
Old 10-08-2007, 03:01 PM THREAD STARTER               #6 (permalink)
Account Closed
Join Date: Jul 2007
Posts: 349
mike1023 will become famous soon enoughmike1023 will become famous soon enoughmike1023 will become famous soon enough
 



nice one!
mike1023 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:33 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger