WebmasterLingo
JustEdge Dedicated Servers

Go Back   WebmasterLingo > Programming Corner
User Name
Password

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old June 7th, 2004, 12:03 PM   #1
Revenant
Registered User
 
Join Date: May 2004
Location: Chicago, IL US of A
Posts: 110
Revenant is off the scale
Send a message via AIM to Revenant Send a message via MSN to Revenant Send a message via Yahoo to Revenant
set a password on ANY page ? :o :o

ey, im still workn on that other script to ban ips from submittin a form again, so in the meantime, ill show ya how to slap a pw on any page at all. first we gotta set the page, we'll call it admin.php [this is the only page we're going to need]

Code:
<? /* set the variables */ $admin_password="var"; // the password $submit="Submit"; // the submit button's function if(!isset($mode)){$mode="login";} // if you haven't logged in, this mode will set itself to the index. switch($mode){ case("login"): // this starts the login mode page echo"<link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\">"; echo"<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\" width=\"100%\">"; echo"<tr>"; echo"<td align=\"center\">"; echo"<br><br><br>Login"; // text left of the text field echo"</td>"; echo"</tr>"; echo"</table>"; echo"<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\" width=\"100%\">"; echo"<tr>"; echo"<td width=\"30%\" height=\"100\"></td>"; echo"<td align=\"center\">"; echo"<form action=\"admin.php?mode=index\" method=\"post\">"; // starts the form echo"<input type=\"password\" name=\"password\" size=\"15\">"; // password field echo"<input type=\"submit\" value=\" Login \">"; echo"</form>"; echo"</td>"; echo"<td width=\"30%\"></td>"; echo"</tr>"; echo"</table>"; break; // ends the mode "login" ?>


i have to go right, but ill finish this off later,
rev
__________________
// Rev
// Ivan Alfaro
-- Professional Web Developer
Revenant is offline   Reply With Quote
Old June 7th, 2004, 08:17 PM   #2
wicked_gal00
Registered User
 
Join Date: May 2004
Location: Canada
Posts: 54
wicked_gal00 is off the scale
Send a message via AIM to wicked_gal00 Send a message via Yahoo to wicked_gal00
I don't know much about php, but wouldn't people be able to get the password from the souce? Or do you disable the property with chmod? I'm not exactly sure how that works...
wicked_gal00 is offline   Reply With Quote
Old June 7th, 2004, 08:29 PM   #3
Matt
Web Junky
 
Join Date: Dec 2003
Posts: 73
Matt is off the scale
Quote:
Originally posted by wicked_gal00
I don't know much about php, but wouldn't people be able to get the password from the souce? Or do you disable the property with chmod? I'm not exactly sure how that works...
Only html will be parsed in the source code. When you go to a .php page, and you view source, it doesn't show all the includes and variables, does it?
__________________
WebmasterLingo.com Team
Forum Rules

"Anyone who has never made a mistake has never tried anything new" - Albert Einstein
Matt is offline   Reply With Quote
Old June 7th, 2004, 08:44 PM   #4
wicked_gal00
Registered User
 
Join Date: May 2004
Location: Canada
Posts: 54
wicked_gal00 is off the scale
Send a message via AIM to wicked_gal00 Send a message via Yahoo to wicked_gal00
Oh I see, so only the echo lines will show?
Is there no way to get at the rest of the code?
wicked_gal00 is offline   Reply With Quote
Old June 7th, 2004, 09:01 PM   #5
Matt
Web Junky
 
Join Date: Dec 2003
Posts: 73
Matt is off the scale
Quote:
Originally posted by wicked_gal00
Oh I see, so only the echo lines will show?
Is there no way to get at the rest of the code?
Unless the server get's hacked, I don't think you can get the variable values.
__________________
WebmasterLingo.com Team
Forum Rules

"Anyone who has never made a mistake has never tried anything new" - Albert Einstein
Matt is offline   Reply With Quote
Old June 8th, 2004, 09:31 AM   #6
ZYV
PHP addict
 
Join Date: Dec 2003
Location: Russia, Nizhny Novgorod
Posts: 71
ZYV is off the scale
Send a message via ICQ to ZYV Send a message via AIM to ZYV
Good start, but doesn't do much ATM
ZYV is offline   Reply With Quote
Old June 8th, 2004, 04:07 PM   #7
Marshall
Registered User
 
Join Date: May 2004
Posts: 70
Marshall is off the scale
Send a message via AIM to Marshall
Id suggest using a cookie so if they enter the password at one page they wont have to re enter it after any link they click, will make it a bit more user friendly.
Marshall is offline   Reply With Quote
Old June 8th, 2004, 09:30 PM   #8
Revenant
Registered User
 
Join Date: May 2004
Location: Chicago, IL US of A
Posts: 110
Revenant is off the scale
Send a message via AIM to Revenant Send a message via MSN to Revenant Send a message via Yahoo to Revenant
and heres the rest >>


Code:
case("index"): if($password==$admin_password){}else{header("Location: admin.php?mode=login");exit;} echo"content here"; // :D Enjoy !!! break;}



so in closing, this is the end result for admin.php >>
Code:
<? /* set the variables */ $admin_password="var"; // the password $submit="Submit"; // the submit button's function if(!isset($mode)){$mode="login";} // if you haven't logged in, this mode will set itself to the index. switch($mode){ case("login"): // this starts the login mode page echo"<link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\">"; echo"<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\" width=\"100%\">"; echo"<tr>"; echo"<td align=\"center\">"; echo"<br><br><br>Login"; // text left of the text field echo"</td>"; echo"</tr>"; echo"</table>"; echo"<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\" width=\"100%\">"; echo"<tr>"; echo"<td width=\"30%\" height=\"100\"></td>"; echo"<td align=\"center\">"; echo"<form action=\"admin.php?mode=index\" method=\"post\">"; // starts the form echo"<input type=\"password\" name=\"password\" size=\"15\">"; // password field echo"<input type=\"submit\" value=\" Login \">"; echo"</form>"; echo"</td>"; echo"<td width=\"30%\"></td>"; echo"</tr>"; echo"</table>"; break; // ends the mode "login" case("index"): if($password==$admin_password){}else{header("Location: admin.php?mode=login");exit;} echo"content here"; break; } ?>


enjoy !, if you have any questions, go hed n ask.
__________________
// Rev
// Ivan Alfaro
-- Professional Web Developer
Revenant is offline   Reply With Quote
Old June 8th, 2004, 10:08 PM   #9
WorldBuilder
Big Daddy
 
Join Date: Jan 2004
Location: Boston, MA
Posts: 380
WorldBuilder is off the scale
Send a message via AIM to WorldBuilder
Whatever happened to just using .htaccess in Apache?! LOL

Chris
__________________
My Site | My Blog
"The world is a dangerous place, not because of those who do evil, but because of those who look on and do nothing."
"Insanity is doing the same thing over and over again, expecting different results"
--Albert Einstein
WorldBuilder is offline   Reply With Quote
Old June 8th, 2004, 10:13 PM   #10
WorldBuilder
Big Daddy
 
Join Date: Jan 2004
Location: Boston, MA
Posts: 380
WorldBuilder is off the scale
Send a message via AIM to WorldBuilder
Ok, since I'm still really new to PHP, answer me this probably stupid question. What is this supposed to DO?

I set it up here for kicks:

www.bartlett-family.net/test/admin.php

As you can see, it's only a login box. WHAT'S the login? What am I missing, eh?!

Chris
__________________
My Site | My Blog
"The world is a dangerous place, not because of those who do evil, but because of those who look on and do nothing."
"Insanity is doing the same thing over and over again, expecting different results"
--Albert Einstein
WorldBuilder is offline   Reply With Quote
Old June 8th, 2004, 10:28 PM   #11
Revenant
Registered User
 
Join Date: May 2004
Location: Chicago, IL US of A
Posts: 110
Revenant is off the scale
Send a message via AIM to Revenant Send a message via MSN to Revenant Send a message via Yahoo to Revenant
it shud be var .... if you dont mind, cud i see the code you put in ? [just to make sure nothing's wrong]
__________________
// Rev
// Ivan Alfaro
-- Professional Web Developer
Revenant is offline   Reply With Quote
Old June 9th, 2004, 01:00 AM   #12
Marshall
Registered User
 
Join Date: May 2004
Posts: 70
Marshall is off the scale
Send a message via AIM to Marshall
World try using this, filename can be whatever you want its set to automatically detect it

Code:
<?php /* set the variables */ $admin_password="var"; $submitted = $_POST['password']; if(!isset($_POST['submit']) || $_POST['password'] != $admin_password){ echo'<link rel="stylesheet" type="text/css" href="css/css.css">'; echo'<table cellspacing="0" cellpadding="5" border="0" width="100%">'; echo'<tr>'; echo'<td align="center">'; echo'<br><br><br>Login'; // text left of the text field echo'</td>'; echo'</tr>'; echo'</table>'; echo'<table cellspacing="0" cellpadding="5" border="0" width="100%">'; echo'<tr>'; echo'<td width="30%" height="100"></td>'; echo'<td align="center">'; if(isset($_POST['password'])){ if($_POST['password'] != $admin_password){ echo '<font color="red">Incorrect Password</font>'; } } echo'<form action="'.$_SERVER['self'].'" method="post">'; // starts the form echo'<input type="password" name="password" size="15">'; // password field echo'<input type="submit" value=" Login " name="submit">'; echo'</form>'; echo'</td>'; echo'<td width="30%"></td>'; echo'</tr>'; echo'</table>'; }else{ echo 'WOAH you got the password baby!'; //place content here } ?>
Marshall is offline   Reply With Quote
Old June 10th, 2004, 01:03 AM   #13
Revenant
Registered User
 
Join Date: May 2004
Location: Chicago, IL US of A
Posts: 110
Revenant is off the scale
Send a message via AIM to Revenant Send a message via MSN to Revenant Send a message via Yahoo to Revenant
good job marshall, specifically the "WOAH you got the password baby!" bit
__________________
// Rev
// Ivan Alfaro
-- Professional Web Developer
Revenant is offline   Reply With Quote
Old June 21st, 2004, 03:07 PM   #14
SW-Demon
Registered User
 
Join Date: Jun 2004
Location: Russia\\N.Novgorod
Posts: 3
SW-Demon is off the scale
The "hole" in the site's defense is usually located not in the lines, where you check password, but in the lines, that follow them, that you are actualy protecting. In your case it is:

echo 'WOAH you got the password baby!'; //place content here

You don't tell us, what will be there, so carefully check this part of the script.
SW-Demon is offline   Reply With Quote
Old June 29th, 2004, 06:51 AM   #15
v3x0rg
Registered User
 
Join Date: Jun 2004
Posts: 7
v3x0rg is off the scale
If you don't have a clue about variables and all that, you can try this simple tutorial for beginners: http://na3k.net/tutorials.php?outid=100&section=php
v3x0rg is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -5. The time now is 05:25 AM.

JustEdge Dedicated Servers