[advanced search]
24 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Webmaster Tutorials
User Name
Password

Old 03-15-2006, 01:17 PM   · #1
RageD
Senior Member
 
Name: Dennis
Location: Joliet, Illinois
Trader Rating: (41)
Join Date: Apr 2005
Posts: 1,124
NP$: 2029.10 (Donate)
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 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
}
// 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


Please register or log-in into NamePros to hide ads

Last edited by RageD : 03-15-2006 at 01:23 PM.
RageD is online now   Reply With Quote
Old 03-17-2006, 03:27 AM   · #2
bbalegere
Senior Member
 
bbalegere's Avatar
 
Name: Bharat Balegere
Location: Bangalore
Trader Rating: (15)
Join Date: Jul 2005
Posts: 1,146
NP$: 15.60 (Donate)
bbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nice
Simple but effective.
bbalegere is offline   Reply With Quote
Old 03-17-2006, 03:38 AM   · #3
wackyjoe
NamePros Regular
 
Trader Rating: (4)
Join Date: Dec 2005
Posts: 206
NP$: 270.00 (Donate)
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   Reply With Quote
Old 03-17-2006, 12:26 PM   · #4
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,402
NP$: 434.65 (Donate)
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
$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']){
         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   Reply With Quote
Old 03-17-2006, 12:48 PM   · #5
Jim_
NamePros Regular
 
Jim_'s Avatar
 
Name: Jim, of course
Location: Philadelphia
Trader Rating: (20)
Join Date: Aug 2005
Posts: 558
NP$: 14.30 (Donate)
Jim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of light
Save The Children
Or, you could use a session cookie...
PHP Code:
<?php
$adminpass
= "testpassword";
session_start();
if(
$_GET['act']=="login"){
  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>";
}
?>
__________________
woop woop
Jim_ is offline   Reply With Quote
Old 03-17-2006, 02:55 PM   · #6
stscac
A Wealth of Knowledge
 
stscac's Avatar
 
Trader Rating: (44)
Join Date: Aug 2004
Posts: 3,784
NP$: 14020.20 (Donate)
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   Reply With Quote
Old 03-22-2006, 10:15 AM   · #7
markkk
NamePros Regular
 
Trader Rating: (3)
Join Date: Jul 2005
Posts: 221
NP$: 328.50 (Donate)
markkk is on a distinguished road
thanks a lot..
markkk is offline   Reply With Quote
Old 03-22-2006, 11:16 PM   · #8
sacx13
NamePros Regular
 
Trader Rating: (8)
Join Date: Mar 2006
Posts: 394
NP$: 286.68 (Donate)
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!="")
    if (
$username==$u && $password==$p)
    {
        
// 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   Reply With Quote
Old 03-24-2006, 02:59 PM   · #9
RageD
Senior Member
 
Name: Dennis
Location: Joliet, Illinois
Trader Rating: (41)
Join Date: Apr 2005
Posts: 1,124
NP$: 2029.10 (Donate)
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 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 online now   Reply With Quote
Old 03-31-2006, 03:27 AM   · #10
sacx13
NamePros Regular
 
Trader Rating: (8)
Join Date: Mar 2006
Posts: 394
NP$: 286.68 (Donate)
sacx13 is on a distinguished road
Lightbulb

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


Regards
sacx13 is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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
Forum Jump

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

Site Sponsors
http://www.mobisitetrader.com/ Build your NameBrand Custom Logo Design
Advertise your business at NamePros
All times are GMT -7. The time now is 09:12 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0