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 > Webmaster Tutorials
Reload this Page Using PHP for Password Identification!

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search
0 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 03-15-2006, 01:17 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse

Using PHP for Password Identification!


This is an alternative to Javascript and all other ways of password identification for a page view! You can also use MySQL for multiple kinds of passwords, but if you only want a couple, this is the way to go: (This requires NO MySQL)

PHP Code:
<?php
// Let's define the page that we will see the login form & page title
$pagetitle "Page Title Here";
if(
$page == ""){ ?>
<HTML>
<TITLE><?php echo($pagetitle); ?></TITLE>
<BODY>
<form name="login" method="post" action="?page=login">
Password: <input type=password name="password"><br>
<input type=submit value="Login"><input type=reset>
</form>
</BODY>
</HTML>
<?php
// Let's end that section with the following bracket
????: NamePros.com http://www.namepros.com/webmaster-tutorials/177083-using-php-for-password-identification.html
}
// Start the login page
if($page == "login"){
// The value '$password' comes from name="password" in the password field
    
if($password !== "PasswordHere"){
         echo(
'Incorrect Password');
         exit;
     }
     else{
          echo(
'You are now logged in!!  Page content goes here!');
     }
}
?>
-Thanks

-RageD
Last edited by RageD; 03-15-2006 at 01:23 PM.
RageD is offline  
Old 03-17-2006, 03:27 AM   #2 (permalink)
Senior Member
 
bbalegere's Avatar
Join Date: Jul 2005
Location: Bangalore
Posts: 1,270
bbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nice
 



Simple but effective.
bbalegere is offline  
Old 03-17-2006, 03:38 AM   #3 (permalink)
NamePros Regular
Join Date: Dec 2005
Posts: 210
wackyjoe is on a distinguished road
 



thats preety unsecure.

but for a small site with not much traffic its good...

btw if Globals are turned off...HIGHELY RECCOMEMDED

$page = $_GET['page'];
wackyjoe is offline  
Old 03-17-2006, 12:26 PM   #4 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



Hey,
The script would be good for an admin panel or something similar.
I might like to make a few additions to your script - add cookies so you won't have to login every time. the 3600 is in seconds - that's an hour. Change if you wish. (86400 is a day).

PHP Code:
<?php
// Let's define the page that we will see the login form & page title
????: NamePros.com http://www.namepros.com/showthread.php?t=177083
$pagetitle "Page Title Here";

setcookie("TestCookie""hello");
if(empty(
$_COOKIE['TestCookie'])) { die("Cookies disabled!"); } else { setcookie("TestCookie""hello"time()-3600); }

if(empty(
$_COOKIE['adminformpassword'])){ ?>
<HTML>
<TITLE><?php echo($pagetitle); ?></TITLE>
<BODY>
<form name="login" method="post" action="?page=login">
Password: <input type=password name="password"><br>
<input type=submit value="Login"><input type=reset>
</form>
</BODY>
</HTML>
<?php
// Let's end that section with the following bracket
}
// Start the login page
if($page == "login"){
// The value '$password' comes from name="password" in the password field
    
$password $_POST['password'];
    if(
$password == "YourPasswordHere") {
    
setcookie("adminformpassword"md5($password), time()+3600);
    }
    if(
md5($password) != $_COOKIE['adminformpassword']){
????: NamePros.com http://www.namepros.com/showthread.php?t=177083
         echo(
'Incorrect Password');
         exit;
    }
     else
    {
          echo(
'You are now logged in!!  Page content goes here!');
     }
}
?>
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 03-17-2006, 12:48 PM   #5 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 608
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
Or, you could use a session cookie...
PHP Code:
<?php
$adminpass 
"testpassword";
session_start();
if(
$_GET['act']=="login"){
????: NamePros.com http://www.namepros.com/showthread.php?t=177083
  if(
$_POST['passwordx']==$adminpass){
    
$_SESSION['logged_in'] = md5($adminpass);
    echo 
"Logged in.";
  }
}
if(
$_GET['act']=="logout"){
  
session_unset();
  echo 
"Logged out.";
}
if(isset(
$_SESSION['logged_in']) && $_SESSION['logged_in']==md5($adminpass)) {
//admin is logged in
//display page here
} else {
//admin is not logged in, so show login form
echo "<form action=\"admin.php?act=login\" method=\"post\"><input type=\"password\" name=\"passwordx\"><input type=\"submit\" value=\"Login\"></form>";
}
?>
__________________
ask me about the internet
Jim_ is offline  
Old 03-17-2006, 02:55 PM   #6 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,803
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



This sort of thing would qualify to be in the CODE section of the Programming section, but I also think it is fitting to put in the Webmaster Tutorial section.



-Steve
stscac is offline  
Old 03-22-2006, 10:15 AM   #7 (permalink)
NamePros Regular
Join Date: Jul 2005
Posts: 220
markkk is on a distinguished road
 



thanks a lot..
markkk is offline  
Old 03-22-2006, 11:16 PM   #8 (permalink)
NamePros Regular
Join Date: Mar 2006
Posts: 397
sacx13 is on a distinguished road
 



Another simple code


My code is reading the passwords from a simple file. The user and passwords are delimited by comas. Ex
user1,pass1
user2,pass2

PHP Code:
<?php
 $username
=$_POST['username'];
 
$password=$_POST['password'];
 
$handle fopen('/etc/php.pas',"r");

while(!
feof($handle))
{
$line fgets($handle,1024);
list(
$u,$p) = explode(',',$line);

$u trim($u);
$p trim($p);
    if (
$username!="")
????: NamePros.com http://www.namepros.com/showthread.php?t=177083
    if (
$username==$u && $password==$p)
????: NamePros.com http://www.namepros.com/showthread.php?t=177083
    {
        
// just add your session cookies here and etc.
        
header("Location: test.html");
        exit();
    }
}

fclose($handle);
?>
Last edited by sacx13; 03-22-2006 at 11:17 PM. Reason: Errata :)
sacx13 is offline  
Old 03-24-2006, 02:59 PM THREAD STARTER               #9 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse
Yep If you wanted to be very technical and secure you could just create a quick MySQL connect script and encrypt everything to a DB... You could use md5 encryption, or whatever you wanted..

-RageD
RageD is offline  
Old 03-31-2006, 03:27 AM   #10 (permalink)
NamePros Regular
Join Date: Mar 2006
Posts: 397
sacx13 is on a distinguished road
 




For a simple page you dont need a mysql database for authentication ...


Regards
sacx13 is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 01:39 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM

 
All times are GMT -7. The time now is 12:58 AM.

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