TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-22-2009, 02:21 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 103
Thanks: 10
Peuplarchie is on a distinguished road
Application Add a sign-up feature to a flat file login script

Good day to you all,
I'm working on a flat file login script and I would like to add a sign-up feature to it with a email confirmation process.

Here is my code :

PHP Code:
<?php
//sessions must be initialized prior to any output if output buffering if off
session_start();

//the list of files containing passwords
$files = array(
    
"pass.txt"
    
"test/pass2.txt",
    
"admin/pass3.txt"
);

//if list of users not set create a new array
if(!isset($_SESSION['users']))
    
$_SESSION['users'] = array();
    
if(isset(
$_POST['username']) && isset($_POST['password'])){
    
    
//need to remove slashes from POST if magic_quotes are on 
    
if(get_magic_quotes_gpc()){
        
$_POST['username'] = stripslashes($_POST['username']);
        
$_POST['password'] = stripslashes($_POST['password']);
    }            
    
    
$userFound false//we need this to exit the loops
    
foreach($files as $file){ //loop every file in the $files array
        
if($fh fopen($file"r")){
            while(!
feof($fh) && !$userFound){ //while not the end of the current file or the user was not found
                
list($username$password$url) = explode(","fgets($fh,1024));
                
                if((
$username == $_POST['username']) && ($password $_POST['password'])){
                    
$_SESSION['username'] = $username;
                    
$_SESSION['present'] = true;
                    
$_SESSION['legal'] = true;
                    
$_SESSION['profile'] = $username.".txt";
                    
array_push($_SESSION['users'], $username); //add the current user to the list of users
                    
header("Location: ".$url);
                    
$userFound true//confirm that the user was found
                    
                    
                
}    
            }
            
            
fclose($fh);
            
//we need to use break to exit the foreach loop if the user is found in one of the files
            
if($userFound)
                break;
        } else
            echo 
"Unable to complete";
    }
    if(!
$userFound)
        
login('Invalid Member name or Password.<br />');
} else {
    
login();
}
?>
<?php

function login($response='Welcome visitor !') {
?>
the user, password and redirection path are listed like the following in the files :

user, pass, path
user, pass, path

How can I add this sign in feature, user would click on sign in, fill a form with his/her full name as user, no space, choose a password, an email would be send and there would be an link to confirm, then the user would be added to the really list.


Thanks!
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 10-22-2009, 10:52 PM   #2 (permalink)
The Addict
 
adamdecaf's Avatar
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

You would just store the account in the database like you normally would, only then you set a field to something similar to "verified" or "enabled" and set the value to 0/1, true/false, yes/no. Then in another record you could have a 'secret' and random string of characters that corresponds to the random string in the verification email.

Code:
Database:
  -- username
  -- password
  -- enabled
  -- secret_code
Code:
Email:

Verify your account!
http://mysite.com/verify?code={random_string}
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 10-23-2009, 03:34 AM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

Just make sure those flat files are below the webroot so basic users can not access them.

Why are you using a flat text file instead of a database or at least XML (XML will be easier to parse when large amounts come).
__________________

Village Idiot is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy to Modify Login Script with Hierarchical User Permissions and XML Account File Wildhoney Script Giveaway 4 05-04-2011 07:11 AM
Txt based login with 3 different or more password file to search in or list ? Peuplarchie Absolute Beginners 1 07-27-2008 07:48 PM
Flat file array, replace 3rd key value based on itself. Peuplarchie Absolute Beginners 1 07-22-2008 01:38 AM
Registration & Login Script Shauny_B General 4 05-15-2008 06:15 PM
First Login Script StevenF Absolute Beginners 33 02-15-2008 03:13 PM


All times are GMT. The time now is 08:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design